Skip to content

Example of how you can use OpenAPI with AWS API Gateway, Also includes integrations with AWSLambda, AWS Cognito, AWS SNS and CloudWatch logs

License

Notifications You must be signed in to change notification settings

rpstreef/openapi-tf-example

Repository files navigation

OpenAPI with AWS API Gateway, Lambda, Cognito, SNS and CloudWatch logs

This repo only deploys the infrastructure via Terraform. The source code, this repo, will be deployed automatically via AWS CodePipeline. By default, it's configured to automatically deploy at every push to the master branch.

Check the companion articles series 'OpenAPI' on dev.to.

Get started

The essentials

  • Download Terraform v0.12.x here
  • You will need Node v12.x from here
  • Git, to clone this Repo, from here
  • Create a free AWS account (requires credit card) here
  • Finally, download the AWS CLI tool
  • Setup your AWS local profile, see this guide how it's done.
  • Manually setup an AWS S3 Bucket for Terraform state storage.

To get the API running

If you meet all the pre-requisites, do the following

  • In your AWS development account create the S3 bucket for your Terraform state files.
    • Optionally, encrypt the S3 bucket and enable versioning such that you can do a rollback.
  • git clone this repo.
  • Change your AWS credentials profile name in these files:
    • ./env/dev/remote-backend.tf
    • ./env/dev/dev.tfvars
  • Run npm install and then execute npm run dev-init, this will:
    • Initialize the Terraform project for the 'dev' environment, and synchronize the state with the cloud stored .tfstate file.
    • If you run it a second time, it will fail on the workspace creation, this is not an issue (the workspace already exists)
  • Run npm run dev-infra to prepare the deployment to your AWS account.
    • Note: this repo contains the node source code that the CodePipeline will deploy to the AWS Lambda and Lambda-layer.
    • Confirm with yes to deploy, anything else will cancel the deployment

See my full guide on dev.to for more information about this project

ps. I'm aware the gulp file doesn't exit nicely, i'm not an expert. Any pull requests or issue reports with pointers is definitely appreciated.

VS Code plugins used

Running costs

There are no costs associated with deploying any of this on AWS, there is Free Tier coverage for limited free use.

The following services are deployed with Terraform;

  • AWS Cognito
  • AWS API Gateway
  • AWS Lambda & Lambda Layer
  • AWS IAM
  • (Added) CloudWatch Alarms, costs will be incurred for enabling Detailed Monitoring for API Gateway (!)
  • (Added) AWS CodePipeline, and CodeBuild with Github as source repository. There's a free tier for:

About

Example of how you can use OpenAPI with AWS API Gateway, Also includes integrations with AWSLambda, AWS Cognito, AWS SNS and CloudWatch logs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published