AWS/CDK

[AWS CDK] Test the Function (Hit counter)

brightlightkim 2022. 3. 29. 06:42

Issue a few test requests

Let’s issue a few requests and see if our hit counter works. You can also use your web browser to do that:

curl https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod/
curl https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod/
curl https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod/hello
curl https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod/hello/world
curl https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod/hello/world

Open DynamoDB console

  1. Go to the DynamoDB console.
  2. Make sure you are in the region where you created the table.
  3. Select Tables in the navigation pane and select the table that starts with CdkWorkdShopStack-HelloHitCounterHits.
  4. Open the table and select “Items”.
  5. You should see how many hits you got for each path.
  6.  
  7. Try hitting a new path and refresh the Items view. You should see a new item with a hits count of one.

Good job!

The cool thing about our HitCounter is that it’s quite useful. It basically allows anyone to “attach” it to any Lambda function that serves as an API Gateway proxy backend and it will log hits to this API.

Since our hit counter is a simple JavaScript class, you could package it into an npm module and publish it to npmjs.org, which is the JavaScript package manager. Then, anyone could npm install it and add it to their CDK apps.

'AWS > CDK' 카테고리의 다른 글

[AWS CDK] cdk-dynamo-table-viewer  (0) 2022.04.05
[AWS CDK] Using Construct Libraries  (0) 2022.03.30
[AWS CDK] Granting Permissions  (0) 2022.03.29
[AWS CDK] CLOUDWATCH LOGS  (0) 2022.03.29
[AWS CDK] DEFINE RESOURCES  (0) 2022.03.29