This is an example of how AWS AppConfig can be used with AWS Lambda and Lambda Extensions. Using AppConfig to separate your application configuration from your application code is good practice. By using that, you are able to deploy configuration changes independently from your code. AWS AppConfig helps us achieve that.
This example will deploy a sample serverless applications with AWS AppConfig and the AppConfig Lambda layer needed for AWS Lambda Extensions using AWS SAM. These are the resources being deployed:
- Lambda Function
- Lambda IAM Role
- Lambda Permissions for AppConfig
- HTTP API
- AppConfig Application
- AppConfig Environment
- AppConfig Deployment Strategy
- AppConfig Configuration Profile
- AppConfig Hosted Configuration Version
- AppConfig Deployment
- Install AWS SAM CLI.
- Build using AWS SAM CLI.
sam build
- Deploy using AWS SAM CLI and follow prompts.
sam deploy --guided
- Use HTTP API endpoint from SAM CLI output to test application. If successfully deployed, you should get the following message.
"Hello from Lambda!"
- Open AppConfig in the AWS Console and browse to the hosted configuration for the deployed application. Link available in the output of SAM CLI after deployment.
- Click "Create" and update the content with new configuration. Save by clicking "Create hosted configuration version".
{
"isEnabled": true,
"messageOption": "AppConfig"
}
- Click "Start deployment" and select the environment, the latest version of the hosted configuration, and the deployment strategy. Press "Start deployment" to start the deployment of the new configuration version.
- If validation of the updated configuration passes, you will be sent to the status page of the deployment.
- Test the new configuration by using the HTTP API endpoint from SAM CLI output. Remember that the AWS AppConfig extension uses caching that is configureable in the SAM template.
"Hello from AppConfig!"
- The initial configuration is deployed using the AppConfigLambdaConfigurationVersion resource in template.yaml.
AppConfigLambdaConfigurationVersion:
Type: AWS::AppConfig::HostedConfigurationVersion
Properties:
ApplicationId: !Ref AppConfigLambdaApplication
ConfigurationProfileId: !Ref AppConfigLambdaConfigurationProfile
Content: '{ "isEnabled": false, "messageOption": "AppConfig" }'
ContentType: 'application/json'
- The validation schema is deployed using the AppConfigLambdaConfigurationProfile resource in template.yaml.
AppConfigLambdaConfigurationProfile:
Type: 'AWS::AppConfig::ConfigurationProfile'
Properties:
Name: AppConfigLambda
ApplicationId: !Ref AppConfigLambdaApplication
LocationUri: hosted
Validators:
- Content: '{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "isEnabled": { "type": "boolean" }, "messageOption": { "type": "string", "minimum": 0 } }, "required": ["isEnabled", "messageOption"] }'
Type: JSON_SCHEMA
- The caching and timeout behavior of AppConfig can be changed by uncommenting and changing the values in template.yaml.
# AWS_APPCONFIG_EXTENSION_POLL_INTERVAL_SECONDS: 45
# AWS_APPCONFIG_EXTENSION_POLL_TIMEOUT_MILLIS: 3000