While I coded this application on a Windows 10 machine, I used Bash shell for scripting various activities. I used Windows Subsystem for Linux (WSL) extensively for deployment and testing.
However, the main code and templates should work in either Windows or Linux environments, using AWS and SAM CLIs.
AWS CLI is needed for configuring AWS credentials and creating S3 bucket for code deployment. Occassionally, I used it to delete CloudFormation stacks in rollback state. Below are the details of AWS CLI versions I used.
On Windows:
PS beginning-aws-lambda> aws --version
aws-cli/1.18.113 Python/3.8.2 Windows/10 botocore/1.17.36
On WSL:
$ beginning-aws-lambda > aws --version
aws-cli/2.0.57 Python/3.9.0 Linux/4.4.0-18362-Microsoft source/x86_64.ubuntu.18
SAM CLI is needed to deploy the stacks and invoke Lambda functions.
I used the same version of SAM CLI on both Windows and WSL — v1.6.2.
sam --version
SAM CLI, version 1.6.2
Ubuntu version:
$ ~ > uname -a
Linux pc 4.4.0-18362-Microsoft #1049-Microsoft Thu Aug 14 12:01:00 PST 2020 x86_64 x86_64 x86_64 GNU/Linux
Bash version:
$ ~ > bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
The activities of building, deploying and running this application in Linux environment are all scripted.
The Bash shell scripts are located in scripts folder.
- File: 0-build.sh
- Syntax:
./scripts/0-build.sh
This script packages the application code in the following steps:
- Installs
aws-sdkNPM module inlib-aws-sdk/nodejs/node_modulesfolder. - Installs non-dev dependencies of main
package.jsoninnode_modulesfolder at the root of repo. - Deletes
zipfiles fromsam-buildfolder. - Copies
aws-sdkmodule tosam-build/aws-sdk.zip. - Copies
node_modulestosam-build/beginning-lambda.zip.
- File: 1-deploy.sh
- Syntax:
./scripts/1-deploy.sh
This script creates a S3 bucket to upload the code packaged in previous stage.
It then deploys all three stacks in the following order:
lib-aws-sdklambda-efs-vpcbeginning-lambda
This script seeks user inputs. It prompts for deployment confirmation once after each of the three CloudFormation stacks' changesets are ready.
The script 2-test.sh is built to test individual Lambda functions by invoking them synchronously using their corresponding payloads in test-events folder. However, testing the getAwsDocsRepo Lambda function also serves the purpose of invoking this application.
Steps:
$ beginning-aws-lambda > ./scripts/2-test.sh
Lambda functions: unzipRepoArchive createAttributeFiles getAwsDocsRepo generateCheatSheet
Choose a lambda function:
Enter getAwsDocsRepo at above prompt.
Once the test completes, abort the script using Ctrl+C keyboard command.
A few minutes later, the cheatsheet should be available at http://aws-cloudformation-attributes-cheatsheet.s3-website.us-east-1.amazonaws.com/.
Note that in the URL:
aws-cloudformation-attributes-cheatsheetis the name of the cheatsheet static website S3 bucketus-east-1is the AWS region the application is deployed in.
- S3 bucket names are global. So the deployment script will fail if the S3 bucket names used in the repo already exist. If that happens, simply changing the S3 bucket names in following two locations should fix the issue:
SAM_CLI_S3_BUCKETvariable value in 1-deploy.sh file.awsCfnAttrsCheatSheetSiteNameparameter'sDefaultattribute in template.yml file.
- I once had trouble running the files in WSL due to line endings being different in Windows and Unix. I solved the problem using
dos2unixutility on WSL. Alternatively, you may also configure Git and other Windows tools to retain Unix line endings.