Skip to content

Latest commit

 

History

History

awsappconfig-extension-demo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

AWS AppConfig Extension Demo

This is a demo of AWS Lambda extensions using AWS AppConfig as explained in the blog post Introducing Lambda Extensions.

AWS AppConfig has an available extension to further integrate Lambda and AWS AppConfig. The extension runs a separate local process to retrieve configuration data from the AWS AppConfig service.

Using the AWS AppConfig extension, a function can fetch configuration data faster using a local call rather than over the network. You can dynamically change a function’s external configuration settings during invocations, without having to redeploy the function. As AWS AppConfig has robust validation features, all configuration changes can be tested safely before rolling out to one or more Lambda functions.

The demo uses the AWS Serverless Application Model (AWS SAM) to deploy two Lambda functions which include the AWS AppConfig extension layer.

As extensions share the same permissions as Lambda functions, the SAM template creates function execution roles that allow access to retrieve the AWS AppConfig configuration.

AWS SAM creates an AWS AppConfig application, environment, and configuration profile, storing a loglevel value, initially set to normal.

Requirements

Installation instructions

  1. Create an AWS account if you do not already have one and login.

  2. Clone the repo onto your local development machine:

git clone https://github.com/aws-samples/aws-lambda-extensions
  1. Get the latest Amazon Resource Name (ARN) of the AppConfig Extension for your Region from the AWS AppConfig Documentation. It is in the format arn:aws:lambda:<Region>:<Account>:layer:AWS-AppConfig-Extension:1

  2. Deploy the SAM template from the command line:

cd awsappconfig-extension-demo
sam deploy --stack-name awsappconfig-extension-demo --guided

During the prompts:

  • Accept the default Stack Name awsappconfig-extension-demo.
  • Enter your preferred Region
  • Update the default AppConfigARN if the ARN retrieved in Step 3 is newer.
  • Accept the default AppConfigProfile configuration function environment variable.
  • Accept the defaults for the remaining questions.

SAM deploys the application stack

  1. From the AWS Lambda Management Console, choose each Lambda function prefixed with awsappconfig-extension-demo.

Create a test event with an event payload for each function

{
  "showextensions": "function1"
}
  1. Invoke both functions using the test events. You should receive a response showing a Cold Start and LogLevel set to normal.
{
  "event": {
    "extensions": "function1"
  },
  "ColdStart": true,
  "LogLevel": "normal"
}
  1. Invoke each function again using the same test event. You should receive a response showing the invocation is not a Cold Start and LogLevel set to normal.
{
  "event": {
    "extensions": "function1"
  },
  "ColdStart": false,
  "LogLevel": "normal"
}
  1. From the AWS AppConfig Management Console, select DemoExtensionApplication. Navigate to the Configuration profiles tab. Select the created profile, LoggingLevel. Create a new hosted configuration version 2 as JSON setting the loglevel to verbose
{
  "loglevel": "verbose"
}
  1. Deploy the configuration by chosing Start deployment.
  • For Environment, select Production
  • For Hosted configuration version, select version 2
  • For Deployment strategy, select AllNow

Once the deployment is complete, AWS AppConfig updates the configuration value for both functions. The function configuration itself is not changed.

Running another test invocation for both functions returns the updated value of verbose still without a cold start.

{
  "event": {
    "extensions": "function2"
  },
  "ColdStart": false,
  "LogLevel": "verbose"
}

AWS AppConfig has updated a dynamic external configuration setting for multiple Lambda functions without having to redeploy the function configuration.

Cleanup instructions

From the AWS AppConfig Console, delete the created Hosted configuration version 2

From the AWS Cloudformation Console, select Stacks.

Select the awsappconfig-extension-demo stack, and choose Delete

The Lambda functions and AppConfig resources are deleted.