Skip to content

Latest commit

 

History

History
86 lines (73 loc) · 3.84 KB

File metadata and controls

86 lines (73 loc) · 3.84 KB

Using AWS AppConfig with AWS Lambda Extensions

Description

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

How to install using AWS SAM

  1. Install AWS SAM CLI.
  2. Build using AWS SAM CLI.
sam build
  1. Deploy using AWS SAM CLI and follow prompts.
sam deploy --guided
  1. Use HTTP API endpoint from SAM CLI output to test application. If successfully deployed, you should get the following message.
"Hello from Lambda!"

How to use after deployment

  1. 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.
  2. Click "Create" and update the content with new configuration. Save by clicking "Create hosted configuration version".
{
  "isEnabled": true,
  "messageOption": "AppConfig"
}
  1. 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.
  2. If validation of the updated configuration passes, you will be sent to the status page of the deployment.
  3. 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!"

Notes

  • 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

Contributors

Gunnar Grosch - GitHub | Twitter | LinkedIn