|
| 1 | +# Serverless |
| 2 | + |
| 3 | +This example demonstrates how to store secrets like API keys encrypted in your repository while providing them as environment variables to your AWS Lambda functions. |
| 4 | + |
| 5 | +## Use-cases |
| 6 | + |
| 7 | +- Provide secrets like API keys to your Lambda functions |
| 8 | + |
| 9 | +## Why? |
| 10 | + |
| 11 | +While repository hosting services like Github or Bitbucket have very high security standards it's recommended to not store your unencrypted secrets there. In addition in larger teams not everybody needs to have access to theses secrets of your production environment. |
| 12 | + |
| 13 | +Encrypting your secrets per stage and only adding the encrypted files into your repository is a sensible strategy to fulfill the previously described goals. The passwords to decrypt and encrypt the secrets files should only be shared between the necessary developers over a secure channel. In case you are using a Continuous Integration to deploy your infrastructure obviously this system must be aware of the passwords as well. |
| 14 | + |
| 15 | +## Setup |
| 16 | + |
| 17 | +Since this plugin uses the Serverless plugin `serverless-secrets-plugin` you need to setup the `node_modules` by running: |
| 18 | + |
| 19 | +```bash |
| 20 | +npm install |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### Decrypt and Deploy |
| 26 | + |
| 27 | +In order to deploy the you endpoint simply run |
| 28 | + |
| 29 | +```bash |
| 30 | +serverless deploy --stage dev |
| 31 | +``` |
| 32 | + |
| 33 | +The expected result should be similar to: |
| 34 | + |
| 35 | +```bash |
| 36 | + Error -------------------------------------------------- |
| 37 | + |
| 38 | + Couldn't find the secrets file for this stage: secrets.dev.yml |
| 39 | +
|
| 40 | + For debugging logs, run again after setting SLS_DEBUG env var. |
| 41 | +
|
| 42 | + Get Support -------------------------------------------- |
| 43 | + Docs: docs.serverless.com |
| 44 | + Bugs: github.com/serverless/serverless/issues |
| 45 | +
|
| 46 | + Please report this error. We think it might be a bug. |
| 47 | +
|
| 48 | + Your Environment Information ----------------------------- |
| 49 | + OS: darwin |
| 50 | + Node Version: 6.2.2 |
| 51 | + Serverless Version: 1.2.0 |
| 52 | +``` |
| 53 | +
|
| 54 | +This is happening since the `serverless-secrets-plugin` makes sure a secrets file for the specific stage exists. |
| 55 | +
|
| 56 | +Let's decrypt the secrets file so you can deploy the service. To do so run |
| 57 | + |
| 58 | +```bash |
| 59 | +serverless decrypt --stage dev --password 'va$27dC}9382G7ac6?V' |
| 60 | +``` |
| 61 | + |
| 62 | +The expected result should be similar to: |
| 63 | + |
| 64 | +```bash |
| 65 | +Serverless: Sucessfully encrypted 'secrets.dev.yml.encrypted' to 'secrets.dev.yml' |
| 66 | +``` |
| 67 | + |
| 68 | +Now that you have the unencrypted version of your secrets file this directory you can deploy with |
| 69 | + |
| 70 | +```bash |
| 71 | +serverless deploy --stage dev |
| 72 | +``` |
| 73 | + |
| 74 | +### Encrypt |
| 75 | + |
| 76 | +In case you want to add, update or remove entries in your secrets file simply modify your secrets file. Once you are done encrypt it with |
| 77 | + |
| 78 | +```bash |
| 79 | +serverless encrypt --stage dev --password 'va$27dC}9382G7ac6?V' |
| 80 | +``` |
| 81 | + |
| 82 | +The expected result should be: |
| 83 | + |
| 84 | +```bash |
| 85 | +Serverless: Sucessfully encrypted 'secrets.dev.yml' to 'secrets.dev.yml.encrypted' |
| 86 | +``` |
| 87 | + |
| 88 | +The encrypted file can be checked into your version control system e.g. Git. |
| 89 | + |
| 90 | +### Decrypt and Encrypt the Production Secrets |
| 91 | + |
| 92 | +```bash |
| 93 | +serverless decrypt --stage prod --password 'v2]83WDneGt9AGXv]X6QfP9NW3^J&K3V' |
| 94 | +``` |
| 95 | + |
| 96 | +```bash |
| 97 | +serverless encrypt --stage prod --password 'v2]83WDneGt9AGXv]X6QfP9NW3^J&K3V' |
| 98 | +``` |
| 99 | + |
| 100 | +# Important Note |
| 101 | + |
| 102 | +Make sure the the secrets files are listed in .gitignore to make sure they are never checked into your repository. |
0 commit comments