Skip to content

aws-samples/aws-appconfig-codepipeline-cdk

aws-appconfig-codepipeline-cdk

This sample application demos setup of AWS AppConfig using AWS CDK. AWS AppConfig application is set up to use AWS CodePipeline as configuration store. It also sets up AWS Lambda validator to validate the configuration.

In addition, the project can set up a basic serverless api using Amazon API Gateway backed by AWS Lambda which makes use of AWS AppConfig Lambda extension to query hosted configuration.

Kotlin is used as language runtime to set up both the cdk application and needed lambda functions.

img.png

Project structure

├── infrastructure          # Infrastructure code vi CDK(Kotlin) for AppConfig setup.
├── software                # Holds business logic in AWS lambda functions
│   ├── configvalidator     # Lambda validator for app config configuration
│   └── demofunction        # Sample function to using lambda extension to query app config configurations
└── ...

Prerequisite

  • Make sure you have AWS CDK installed and configured with an aws account you want to use.
  • git-remote-codecommit
  • Ensure you have docker installed and is up and running locally.

Getting started

AppConfig with CodePipeline as Configuration Store

  • Change directory to where infrastructure code lives.
    cd infrastructure
    cdk synth
  • Deploy the CDK application stack named AppConfigCiCdStack. This stack will take care of setting up app config application named ServerlessApplicationConfig with a Test environment which will use codepipeline as configuration store. CodePipeline is also created using a codecommit repository as a source for configurations.
    cdk deploy --app 'cdk.out/' AppConfigCiCdStack

Above command will take care of packaging the configvalidator lambda function as well. Acknowledge security related changes prompt during deployment process. Once completed AppConfig related details are provided as stack output.

  • Once the stack is successfully deployed, You can navigate to your aws account and see the created codepipeline project along with an empty code commit repo. You need to clone the newly created codecommit repo to push a sample config file.
    git clone codecommit://serverless-app-configurations && cd serverless-app-configurations/
  git checkout -b main
  git add .
  git commit -m "Log config"
  git push origin main

Now the codepipeline should trigger automatically and deploy the configuration. It will also invoke the validator handler to validate the configurations.

img.png

Deploy Sample Serverless Application with AppConfig Lambda Extension

  • Deploy ServerlessAppStack. Acknowledge security related changes prompt during deployment process.
  cdk deploy --app 'cdk.out/' ServerlessAppStack

Serverless Api Path is provided as stack output.

  • Validate the api response.
 curl https://<hash>.execute-api.eu-west-1.amazonaws.com/prod/

This will return api gateway proxy request itself as response. But let's see app config in action.

 curl https://<hash>.execute-api.eu-west-1.amazonaws.com/prod/?appConfig=true

This will return the app config configuration which was committed to code commit repository.

  • Now try changing the log level value in the codecommit repo logging.yaml file. Once the config is deployed via codepipeline, try accessing the same api url again. You should be able to see the latest config value in the response.
 curl https://<hash>.execute-api.eu-west-1.amazonaws.com/prod/?appConfig=true

Cleanup

    cdk destroy ServerlessAppStack
    cdk destroy AppConfigCiCdStack

Acknowledge stack deletion when prompted.

Useful commands

  • mvn package compile and run tests
  • cdk ls list all stacks in the app
  • cdk synth emits the synthesized CloudFormation template
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk docs open CDK documentation

Enjoy!

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages