|
1 | | -# Welcome to your CDK TypeScript project |
| 1 | +# API Gateway Asynchronous Lambda Invocation |
2 | 2 |
|
3 | | -This is a blank project for CDK development with TypeScript. |
| 3 | +Sample architecture to process events asynchronously using API Gateway and Lambda and store result in DynamoDB. |
4 | 4 |
|
5 | | -The `cdk.json` file tells the CDK Toolkit how to execute your app. |
| 5 | +## Architecture |
| 6 | + |
6 | 7 |
|
7 | | -## Useful commands |
| 8 | +## Test: |
| 9 | +- `POST` curl command: |
| 10 | +```shell |
| 11 | +curl -X POST https://<API-ID>.execute-api.<REGION>.amazonaws.com/<stage>/job \ |
| 12 | + -H "X-Amz-Invocation-Type: Event" \ |
| 13 | + -H "Content-Type: application/json" \ |
| 14 | + -d '{}' |
| 15 | +``` |
8 | 16 |
|
9 | | -* `npm run build` compile typescript to js |
10 | | -* `npm run watch` watch for changes and compile |
11 | | -* `npm run test` perform the jest unit tests |
12 | | -* `npx cdk deploy` deploy this stack to your default AWS account/region |
13 | | -* `npx cdk diff` compare deployed stack with current state |
14 | | -* `npx cdk synth` emits the synthesized CloudFormation template |
| 17 | +- `GET` curl command to get job details: |
| 18 | +```shell |
| 19 | +# jobId refers the output of the POST curl command. |
| 20 | +curl https://<API-ID>.execute-api.<REGION>.amazonaws.com/<stage>/job/<jobId> |
| 21 | +``` |
| 22 | + |
| 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: |
| 32 | +[1] Set up asynchronous invocation of the backend Lambda function |
| 33 | +https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-integration-async.html |
0 commit comments