In this section of the lab, we will modify our API Gateway Lambda to utilize the boolEnableLimitResults
and intResultLimit
properties of our configuration document to enable a new feature that will limit the number of results returned by API Gateway as well as utilize the value of intResultLimit
to determine how many results to return.
The current state of our configuration document is as follows:
{
"boolEnableLimitResults": false,
"intResultLimit": 0
}
We will first need to modify our Lambda code to implement the limit feature, update our configuration document to turn on the feature and then redeploy our configuration profile to development.
Next, we will update our Lambda application to implement the boolEnableLimitResults
configuration value to turn on the limit results feature code block as well as utilize the value of intResultLimit
to determine the number of results returned in the API response.
Use the following procedure to implement the limit feature toggle.
// add result limit code here
.if ( (parsedConfigData.boolEnableLimitResults) && parsedConfigData.intResultLimit ) {
result = result.splice(0, parsedConfigData.intResultLimit);
}
const response = {
statusCode: 200,
body: result,
};
Note that the limiting feature did not work because the value for boolEnableLimitResults is set to false. We need to update our hosted configuration by changing the value of boolEnableLimitResults to true to enable limiting as well as change the value of intResultLimit to 5 from 0 so that we get results. Then, we will need to redeploy AppConfig to our development environment to allow the API Gateway Lambda to access the updated configuration data.
Use the following procedure to update the hosted configuration data and redeploy it to the development environment.
{
"boolEnableLimitResults": true,
"intResultLimit": 5
}
With the updated configuration deployed, "boolEnableLimitResults": true
and "intResultLimit": 5
are now both available for use by the API Gateway application.
Next, we will verify that the limit feature is now in fact enabled.
{
"statusCode": 200,
"body": [
{
"name": "AWS AppConfig"
},
{
"name": "Amazon SageMaker Studio"
},
{
"name": "Amazon Kendra"
},
{
"name": "Amazon CodeGuru"
},
{
"name": "Amazon Fraud Detector"
}
]
}