Skip to content

Commit 86766c8

Browse files
committed
More docs
1 parent 169030f commit 86766c8

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

examples/powertools-examples-serialization/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,53 @@ started with SAM in [the examples directory](../README.md)
2525

2626
## Test the application
2727

28+
### 1. API Gateway Endpoint
29+
30+
To test the HTTP endpoint, we can post a product to the test URL:
31+
32+
```bash
33+
curl -X POST https://[REST-API-ID].execute-api.[REGION].amazonaws.com/Prod/product/ -H "Content-Type: application/json" -d '{"id": 1234, "name": "product", "price": 42}'
34+
```
35+
36+
The result will indicate that the handler has successfully deserialized the request body:
37+
38+
```
39+
Received request for productId: 1234
40+
```
41+
42+
If we look at the logs using `sam logs --tail --stack-name $MY_STACK`, we will see the full deserialized request:
43+
44+
```json
45+
{
46+
...
47+
"level": "INFO",
48+
"loggerName": "org.demo.serialization.APIGatewayRequestDeserializationFunction",
49+
"message": "product=Product{id=1234, name='product', price=42.0}\n",
50+
...
51+
}
52+
```
53+
54+
### 2. SQS Queue
55+
For the SQS handler, we have to send a request to our queue. We can either construct the Queue URL (see below), or
56+
find it from the SQS section of the AWS console.
57+
58+
```bash
59+
aws sqs send-message --queue-url "https://sqs.[REGION].amazonaws.com/[ACCOUNT-ID]/sqs-event-deserialization-queue" --message-body '{"id": 1234, "name": "product", "price"
60+
```
61+
62+
Here we can find the message by filtering through the logs for messages that have come back from our SQS handler:
63+
64+
```bash
65+
sam logs --tail --stack-name $MY_STACK --filter SQS
66+
```
67+
68+
```bash
69+
{
70+
...
71+
"level": "INFO",
72+
"loggerName": "org.demo.serialization.SQSEventDeserializationFunction",
73+
"message": "products=[Product{id=1234, name='product', price=42.0}]\n",
74+
...
75+
}
76+
77+
```

examples/powertools-examples-serialization/template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Resources:
3232
SQSEventDeserializationFunction:
3333
Type: AWS::Serverless::Function
3434
Properties:
35-
CodeUri: Function
35+
CodeUri: .
3636
Handler: org.demo.serialization.SQSEventDeserializationFunction::handleRequest
3737
Policies:
3838
- Statement:

0 commit comments

Comments
 (0)