Statements | Branches | Functions | Lines |
---|---|---|---|
The purpose of this project is to use AWS CloudFormation to set an SNS Topics delivery retry policy
This application contains the AWS CDK code for deploying an SNS Topic and a Lambda using Nested Stacks. This Lambda Function is then invoked (via a GitHub Action) to set the attributes involved with the SNS Topics delivery retry policy. The paramaters can be configured in .github/workflows/cdk-deploy.yml
(lines 67-79).
Once these pre-requisites have been set up you can log into AWS by running the following command: saml2aws login
.
You can deploy the entire app from your local machine to AWS. To do this you'll need to:
- Configure your
/deployGenericSnsTopic/.env
by taking a copy of/deployGenericSnsTopic/.env.example
and populating it with your AWS credentials. - Run the
package
npm script found in/setTopicAttributes/package.json
- Run the
deploy
npm script found in/deployGenericSnsTopic/package.json
Once you have deployed the app, you should manually go into the AWS Console and invoke the lambda i.e. configure test events and pass in a JSON block as shown in .github/workflows/cdk-deploy.yml
(lines 67-79).
In order for the GithubAction to invoke the set-topic-attributes Lambda we must do the following in the AWS Console:
- Create a new User
IAM -> Users -> Add user
- Username can be something relating to your project e.g.
cdk-set-topic-attributes
- Select
Programmatic access
->Next: Permissions
- Select
Attach existing policies directly
- Add
AWSLambdaRole
- Add
- Click
Next: Tags
- Add the tags specified in
/deployGenericSnsTopic/constants/tags.ts
- Add the tags specified in
Once you have created your new user you must ensure the following secrets are added (Settings -> Secrets):
AWS_ACCESS_KEY_ID_INVOKE_TOPIC_LAMBDA_USER
(which is the access key given when creating the user)AWS_SECRET_ACCESS_KEY_INVOKE_TOPIC_LAMBDA_USER
(which is the secret access key given when creating the user)
To ensure CDK is able to evaluate environment variables during the workflow (GitHub Action), you must ensure the following secrets are added (Settings -> Secrets):
AWS_ACCESS_KEY_ID
AWS_ACCOUNT_ID
AWS_SECRET_ACCESS_KEY
We are able to deploy using CDK via the use of GitHub Actions by defining a workflow. This workflow can be found here:
.github/workflows/cdk-deploy.yml
The project has been configured so it runs prettier for auto-formatting the code as well as xo, which is an ESLint wrapper, in the pre-commit stage.
To use the pre-commit hook on a Windows machine you must use Windows Subsytem for Linux (WSL) or Cygwin.
To bypass the pre-commit hook you can simply add the --no-verify
tag at the end of your commit message. For example:
git commit -m "Example message" --no-verify