Go to Synthetics canary page, and click on Create canary.
Select API canary under Blueprints.
Name it my-api-canary.
Check the I’m using an Amazon API Gateway API checkbox.
Select the Choose API and stage from API Gateway option.
Select the monitoring-app API.
Select the Prod stage.
Your API URL will be automatically selected.
Click on Add HTTP Request.
Select /items under Resource.
Select GET under Method.
Accept all other default configurations and click Save.
On Schedule configure it to run every 1 minute.
Accept all other default configurations and click Create canary.
If you didn’t take a note of your API Url after deploying the sample app, you can always check for its CloudFormation Stack Output Variable of type the following command on your Cloud9 environment terminal.
echo $(aws cloudformation describe-stacks --stack-name monitoring-app --output json | jq '.Stacks[].Outputs[] | select(.OutputKey=="ApiUrl") | .OutputValue' | sed -e 's/^"//' -e 's/"$//')
After a few minutes, you should be presented with a similar screen to observe your canary status.
Let’s see: what happens if we accidentally break our API? Since we are monitoring the GET method for the /items/
route, we are going to modify our get-all-items.js Lambda function in order to introduce a random exception to make our canary fail.
getAllItemsHandler()
method by throwing a new error right after it’s HTTP method validation: if (event.httpMethod !== 'GET') {
throw new Error(`getAllItems only accept GET method, you tried: ${event.httpMethod}`)
}
throw new Error('Sample exception introduction') // <- Sample exception throw
Your getAllItemsHandler() method should look like this:
cd ~/environment/serverless-observability-workshop/code/sample-app
sam build && sam deploy
After a few minutes you should be that your canary is now in a Failed
state.
Click the my-api-canary link to view all additional information about your canary.
In order for us to be able to pass our canary tests again, we are going to switch back to your Cloud9 environment and open the file at /serverless-observability-workshop/code/sample-app/src/handlers/get-all-items.js once again.
throw new Error()
command we introduced in the getAllItemsHandler()
method:throw new Error('Sample exception introduction') // <- Remove exception throw
Your getAllItemsHandler() method should look like this:
cd ~/environment/serverless-observability-workshop/code/sample-app
sam build && sam deploy
After a few minutes you should notice that your canary is again in a Passing
state.