Now that we have created and deployed an AWS AppConfig Configuration Document, it is available to applications to consume the configuration data and use it.
In this section of the lab, we will create an Amazon API Gateway and AWS Lambda Serverless Application that will ultimately consume the configuration data we have deployed to the development environment.
Use the following procedure to create an AWS Lambda.
exports.handler = async (event) => {
let result = getServices();
const response = {
statusCode: 200,
body: result,
};
return response;
};
function getServices() {
return [
{
name: 'AWS AppConfig'
},
{
name: 'Amazon SageMaker Studio'
},
{
name: 'Amazon Kendra'
},
{
name: 'Amazon CodeGuru'
},
{
name: 'Amazon Fraud Detector'
},
{
name: 'Amazon EKS on AWS Fargate'
},
{
name: 'AWS Outposts'
},
{
name: 'AWS Wavelength'
},
{
name: 'AWS Transit Gateway'
},
{
name: 'Amazon Detective'
}
];
}
Note that this block of code simply returns an array of objects (sample list of AWS Services) that includes the name
property.
Use the following procedures to verify the Lambda returns an array of objects (sample list of AWS Services) that includes the name
property:
{
"statusCode": 200,
"body": [
{
"name": "AWS AppConfig"
},
{
"name": "Amazon SageMaker Studio"
},
{
"name": "Amazon Kendra"
},
{
"name": "Amazon CodeGuru"
},
{
"name": "Amazon Fraud Detector"
},
{
"name": "Amazon EKS on AWS Fargate"
},
{
"name": "AWS Outposts"
},
{
"name": "AWS Wavelength"
},
{
"name": "AWS Transit Gateway"
},
{
"name": "Amazon Detective"
}
]
}
Next, we will create an Amazon API Gateway that we will later integrate with the Lambda we just created.
Use the following procedures to create an AWS API Gateway:
Now, we will configure the Amazon API Gateway and AWS Lambda integration so that when we call our API, it will return the results we demonstrated during our AWS Lambda test execution.
Use the following procedures to configure the Amazon API Gateway and AWS Lambda integration:
At this point in the lab, we have created an Amazon API Gateway and integrated it with an AWS Lambda that returns a simple array of JSON objects each of which contains the name property.
Next, we will configure the AWS Lambda to enable AWS AppConfig integration which will include adding permissions for AWS AppConfig to invoke the AWS Lambda as well as modifying the code to retrieve the configuration data for use in our serverless application.