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.
├── 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
└── ...
- 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.
- 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 namedServerlessApplicationConfig
with aTest
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/
- Commit sample config file into the repo.
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.
- 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
cdk destroy ServerlessAppStack
cdk destroy AppConfigCiCdStack
Acknowledge stack deletion when prompted.
mvn package
compile and run testscdk ls
list all stacks in the appcdk synth
emits the synthesized CloudFormation templatecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk docs
open CDK documentation
Enjoy!
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.