aws-samples / asynchronous-event-processing-api-gateway-lambda-cdk

Sample architecture to process events asynchronously using API Gateway and Lambda.
MIT No Attribution
7 stars 2 forks source link

Asynchronous Event Processing with API Gateway and Lambda

Sample architecture to process events asynchronously using API Gateway and Lambda.

Architecture

architecture

A typical workflow looks as following:

  1. The user authenticates against AWS Identity and Access Management (IAM) and obtains security credentials
  2. The user does an HTTP POST request to the /jobs jobs API endpoint, specifying in the request body the job parameters
  3. The jobs API returns to the user an HTTP response containing the job identifier
  4. The jobs API invokes asynchronously the event processing AWS Lambda function
  5. The event processing function processes the event, then puts the job results in the jobs Amazon DynamoDB table
  6. The user does an HTTP GET request to the /jobs/{jobId} jobs API endpoint, with the job identifier from step 3. as {jobId}
  7. The jobs API queries the jobs table to retrieve the job results
  8. The jobs API returns to the user an HTTP response containing the job results

If the event processing fails:

  1. The event processing function sends the event to the error handling function
  2. The error handling function puts the job parameters in the jobs Amazon DynamoDB table
  3. The user can retrieve the job parameters by doing an HTTP GET request to the /jobs/{jobId} jobs API endpoint

If the error handling fails:

  1. The error handling function sends the event to an Amazon EventBridge archive
  2. The user can replay the archived events by using the related Amazon EventBridge feature

Best Practices

Prerequisites

Install on your workstation the following tools:

You should also own or have access to an AWS account.

Setup

Execute the following steps on your workstation:

cd asynchronous-event-processing-api-gateway-api-gateway-lambda-cdk
npx projen
source .env/bin/activate
pre-commit install
pre-commit install --hook-type commit-msg

Test

To run the project tests execute:

npx projen test

Lint

To lint the project code execute:

npx projen synth
npx projen lint

Scan

To perform a security scan of the project code execute:

npx projen synth
npx projen scan

Release

Execute the following steps on your workstation:

...
__version__ = "0.1.0"
...
npx projen
npx projen release
git push
git push --tags

Bootstrap

To bootstrap the AWS CDK in your AWS account execute:

AWS_PROFILE=$YOUR_AWS_PROFILE npx projen bootstrap

Deployment

To deploy your application in your AWS account execute:

AWS_PROFILE=$YOUR_AWS_PROFILE npx projen deploy

Cleanup

To cleanup your application in your AWS account execute:

AWS_PROFILE=$YOUR_AWS_PROFILE npx projen destroy

Try it out

To try the sample architecture included in this repository proceed to:

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.