From 16474c8fa44b68c1012cd966948b2ea67d511ee2 Mon Sep 17 00:00:00 2001 From: "justin.kruse" Date: Sat, 24 Feb 2024 08:20:33 -0600 Subject: [PATCH 1/2] feat: add optional parameter for function name --- guard-lambda/template.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/guard-lambda/template.yaml b/guard-lambda/template.yaml index a79a90eab..039e65a94 100644 --- a/guard-lambda/template.yaml +++ b/guard-lambda/template.yaml @@ -1,11 +1,17 @@ Transform: AWS::Serverless-2016-10-31 +Parameters: + FunctionName: + Type: String + Description: The name of the function + Resources: CloudFormationGuardLambda: Type: AWS::Serverless::Function Properties: Runtime: provided.al2 Handler: guard.handler + FunctionName: !Ref FunctionName # We need to point to the parent directory, so we can use ../guard/* CodeUri: .. Environment: From e951a706d83d4a22ed60cd6166dd5f446b0474d7 Mon Sep 17 00:00:00 2001 From: "justin.kruse" Date: Sat, 24 Feb 2024 09:28:04 -0600 Subject: [PATCH 2/2] chore: update readme with ci/cd steps --- guard-lambda/README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/guard-lambda/README.md b/guard-lambda/README.md index 80ef15b12..98019d554 100644 --- a/guard-lambda/README.md +++ b/guard-lambda/README.md @@ -123,12 +123,50 @@ The Lambda version of the tool is a lightweight wrapper around the core [cfn-gua ### Building and deploying +#### Guided + 1. Make sure docker is running 2. Navigate to `guard-lambda` directory and run `sam build --use-container` to build the code for the Lambda function 3. Run `sam deploy --guided` and complete the interactive workflow. This workflow will create a CloudFormation changeset and deploy it 4. Once it succeeds, the name of the function will be shown in the `CloudFormationGuardLambdaFunctionName` output 5. For subsequent updates, build the code again (step 2) and run `sam deploy` (without `--guided`) +#### CI/CD + +This approach does not require user input and can be used in CI/CD pipelines: + +1. Make sure docker is running +2. Navigate to `guard-lambda` directory and run `sam build --use-container` to build the code for the Lambda function +3. Run `sam package --s3-bucket ` this will create a `.zip` package with the code and dependencies and upload to S3 +4. Run `sam deploy --s3-bucket --stack-name \ + --stack-name \ + --parameter-overrides FunctionName=MyCfnGuardLambda +``` + +or in your `samconfig.toml`: + +```toml +[default.global.parameters] +s3_bucket = "" +stack_name = "" +parameter_overrides = "FunctionName=MyCfnGuardLambda" +``` + +Note: multiple parameters are separated by spaces: `Param1=Value1 Param2=Value2` ## Calling the AWS Lambda Function