In this section we will enable X-ray for the Lambda function to track incoming and outgoing requests to the function, knowing how much time each segment of the function takes. Then we will know where the function is slow and from there easily optimize it.
Open AWS Lambda console.

At book_delete page.

At Edit monitoring tools page.



Open Postman to call api.
2.2 is deleted.

Back to book_delete page.

At CloudWatch page.


At Trace 1-… page. Currently, because we haven’t implemented the SDK patching, the trace map will only show basic blocks (Client -> Lambda Context -> Lambda Function).

Go to the root directory of fcj-book-store-sam-ws8 project. Open the fcj-book-store-sam-ws8/fcj-book-shop/book_delete directory in your editor.
Create a file called requirements.txt with the below content.
aws_xray_sdk

Open the fcj-book-store-sam-ws8/fcj-book-shop/book_delete/book_delete.py and copy the below content to that file.
from aws_xray_sdk.core import patch_all
patch_all()

Open your terminal and run the below commands at the root directory of fcj-book-store-sam-ws8 project to apply updates.
sam build

sam deploy

If prompted to deploy changeset, type y to confirm.

Wait for the Cloudformation stack update to show successfully updated.

Back to book_delete in the AWS console.

Open Postman to recall the DELETE api with the id 4.

Back to CloudWatch page.

At Trace 1-… page. Because we applied SDK patching, the trace map now captures more specific downstream dependencies (such as the S3 bucket node along with DynamoDB connections) natively!

