Skip to content

Commit faa8f8e

Browse files
authored
added background and solution in README.md
1 parent b2a901c commit faa8f8e

File tree

1 file changed

+37
-9
lines changed
  • typescript/api-gateway-async-lambda-invocation

1 file changed

+37
-9
lines changed

typescript/api-gateway-async-lambda-invocation/README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,42 @@ Sample architecture to process events asynchronously using API Gateway and Lambd
55
## Architecture
66
![architecture](./images/architecture.png)
77

8+
## Background:
9+
10+
In Lambda non-proxy (custom) integration, the backend Lambda function is invoked synchronously by default. This is the desired behavior for most REST API operations.
11+
Some applications, however, require work to be performed asynchronously (as a batch operation or a long-latency operation), typically by a separate backend component.
12+
In this case, the backend Lambda function is invoked asynchronously, and the front-end REST API method doesn't return the result.
13+
14+
## Solution:
15+
16+
### API Gateway:
17+
18+
- `POST` `/job`: Integrates with the Lambda function for job submission.
19+
- `GET` `/job/{jobId}`: Direct DynamoDB integration to fetch the job status by jobId.
20+
21+
### DynamoDB Integration:
22+
23+
- The stack includes the DynamoDB table for storing job statuses with jobId as the partition key.
24+
- The Lambda function has permissions to write to the DynamoDB table.
25+
26+
### IAM Role:
27+
- An IAM role is created for API Gateway with permissions to access the DynamoDB table for the GET /job/{jobId} method
28+
29+
### Example structure:
30+
```
31+
/api-gateway-async-lambda-invocation
32+
├── /assets
33+
│ └── /lambda-functions
34+
│ └── job_handler.js
35+
├── /lib
36+
| |-- app.ts
37+
│ └── api-gateway-async-lambda-invocation-stack.ts
38+
├── node_modules
39+
├── package.json
40+
├── cdk.json
41+
└── ...
42+
```
43+
844
## Test:
945
- `POST` curl command:
1046
```shell
@@ -20,14 +56,6 @@ curl -X POST https://<API-ID>.execute-api.<REGION>.amazonaws.com/<stage>/job \
2056
curl https://<API-ID>.execute-api.<REGION>.amazonaws.com/<stage>/job/<jobId>
2157
```
2258

23-
24-
```
25-
In Lambda non-proxy (custom) integration, the backend Lambda function is invoked synchronously by default.
26-
This is the desired behavior for most REST API operations.
27-
Some applications, however, require work to be performed asynchronously (as a batch operation or a long-latency operation), typically by a separate backend component.
28-
In this case, the backend Lambda function is invoked asynchronously, and the front-end REST API method doesn't return the result.
29-
```
30-
31-
### Reference:
59+
## Reference:
3260
[1] Set up asynchronous invocation of the backend Lambda function
3361
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-integration-async.html

0 commit comments

Comments
 (0)