Skip to content

Instantly share code, notes, and snippets.

@ryan-blunden
Last active April 12, 2021 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryan-blunden/a4e7c2e6b0c13e6af9f2d88d4e5a9375 to your computer and use it in GitHub Desktop.
Save ryan-blunden/a4e7c2e6b0c13e6af9f2d88d4e5a9375 to your computer and use it in GitHub Desktop.
AWS SAM template automated embedding of environment variables using the Doppler CLI
template-deployment.yaml

AWS SAM template automated embedding of environment variables using the Doppler CLI

Local development

./deploy-template.sh > template-deploy.yaml;sam local start-api --template template-deploy.yaml;rm template-deploy.yaml;

Deployment

./deploy-template.sh > template-deploy.yaml;sam deploy --template template-deploy.yaml;rm template-deploy.yaml;
#!/usr/bin/env bash
SECRETS=$(jq -r '. | to_entries[] | " \(.key): \(.value)"' <(doppler secrets download --no-file))
ENV_TEMPLATE="Environment:
Variables:"
ENV_VARS="$ENV_TEMPLATE\n$SECRETS"
TEMPLATE=$(cat template.yaml)
echo -e "${TEMPLATE/\#\$ENVIRONMENT/$ENV_VARS}"
# Used by deploy-template.sh to replace `#$ENVIRONMENT` with the list of Doppler secrets
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app
Sample SAM Template for sam-app
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.8
#$ENVIRONMENT
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment