Skip to content

Commit 6b55f2d

Browse files
author
Benedikt Pauwels
committed
added additional steps to readme.md
1 parent 48425c0 commit 6b55f2d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

examples/sam/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,50 @@ The first command will build the source of your application. Using esbuild for b
6464

6565
You can find your API Gateway Endpoint URL in the output values displayed after deployment.
6666

67+
## Execute the functions via API Gateway
68+
69+
Use the API Gateway Endpoint URL from the output values to execute the functions. First, let's add two items to the DynamoDB Table by running:
70+
71+
```bash
72+
curl -XPOST --header 'Content-Type: application/json' --data '{"id":"myfirstitem","name":"Some Name for the first item"}' https://randomid12345.execute-api.eu-central-1.amazonaws.com/Prod/
73+
curl -XPOST --header 'Content-Type: application/json' --data '{"id":"myseconditem","name":"Some Name for the second item"}' https://randomid1245.execute-api.eu-central-1.amazonaws.com/Prod/
74+
````
75+
76+
Now, let's retrieve all items by running:
77+
78+
```bash
79+
curl -XGET https://randomid12345.execute-api.eu-central-1.amazonaws.com/Prod/
80+
````
81+
82+
And finally, let's retrieve a specific item by running:
83+
```bash
84+
https://randomid12345.execute-api.eu-central-1.amazonaws.com/Prod/myseconditem/
85+
```
86+
87+
## Observe the outputs in AWS CloudWatch & X-Ray
88+
### CloudWatch
89+
90+
If we check the logs in CloudWatch, we can see that the logs are structured like this
91+
```
92+
2022-04-26T17:00:23.808Z e8a51294-6c6a-414c-9777-6b0f24d8739b DEBUG
93+
{
94+
"level": "DEBUG",
95+
"message": "retrieved items: 0",
96+
"service": "getAllItems",
97+
"timestamp": "2022-04-26T17:00:23.808Z",
98+
"awsRequestId": "e8a51294-6c6a-414c-9777-6b0f24d8739b"
99+
}
100+
```
101+
102+
By having structured logs like this, we can easily search and analyse them in [CloudWatch Logs Insight](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html). Run the following query to get all messages for a specific `awsRequestId`:
103+
104+
````
105+
filter awsRequestId="bcd50969-3a55-49b6-a997-91798b3f133a"
106+
| fields timestamp, message
107+
````
108+
### AWS X-Ray
109+
As we have enabled tracing for our Lambda-Funtions, we can visit [AWS X-Ray Console](https://console.aws.amazon.com/xray/home#/traces/) and see [traces](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces) and a [service map](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-using-xray-maps.html) for our application.
110+
67111
## Use the SAM CLI to build and test locally
68112
69113
Build your application with the `sam build` command.

0 commit comments

Comments
 (0)