Last active
January 23, 2022 01:57
-
-
Save ranguard/3befa8344678c9fe90f34a81e3a5ca8d to your computer and use it in GitHub Desktop.
CDK + SAM for local lambda devel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Because I use layers, referenced by a SSM Param I need to replace | |
# that in the generated template | |
export LAYERARN="arn:aws:lambda:eu-west-1:xxx:layer:YYYY:1"; | |
export LAYERMATCH="/layers/baseLayer" # <- Param name | |
if [ -z "$STACK" ] | |
then | |
echo "Usage: STACK=xxx gen_sam_template.sh" | |
else | |
cdk synth $STACK --no-staging > template.yaml | |
perl -pi -e 's/$ENV{LAYERMATCH}/$ENV{LAYERARN}/ge' template.yaml | |
echo "template.yaml created and LayerArn set to: $LAYERARN" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## Usage: AWS_REGION=XXX AWS_PROFILE=YYY ./run_local.sh | |
## Note: must be from same dir as template.yaml | |
## which is generated using the gen_sam_template.sh | |
# Get from template.yaml ( see also https://docs.aws.amazon.com/cdk/latest/guide/tools.html#sam ) | |
FUNCTION_REFERENCE=XXXXXXXXX | |
## Create user specific files that can be put into version control, but not | |
## step on each other's toes! | |
export ENVFILE="$USER-env.json" | |
export EVENTFILE="$USER-event.json" | |
# Run | |
sam local invoke --env-vars $ENVFILE --event $EVENTFILE \ | |
--region $AWS_REGION --profile $AWS_PROFILE $FUNCTION_REFERENCE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"FUNCTION_REFERENCE_FROM_TEMPLATE": { | |
"SOME_ENV_KEY: "and-the-value-a-bucket-name-for-example" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment