Code Monkey home page Code Monkey logo

cdk-set-topic-attributes's Introduction

cdk-set-topic-attributes

XO code style Tests

Statements Branches Functions Lines
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).

Deploying to AWS via CDK locally

Pre-requisite utilities

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).

Deploying to AWS via CDK with GitHub Actions

Setting up the GitHub repository

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
  • Click Next: Tags
    • Add the tags specified in /deployGenericSnsTopic/constants/tags.ts

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

Defining a workflow

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

Pre-commit hooks

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.