{"id":13505674,"url":"https://github.com/shaftoe/api-gateway-lambda-cdk-example","last_synced_at":"2025-10-28T18:30:44.840Z","repository":{"id":137704720,"uuid":"236357435","full_name":"shaftoe/api-gateway-lambda-cdk-example","owner":"shaftoe","description":null,"archived":false,"fork":false,"pushed_at":"2020-02-03T15:23:51.000Z","size":13,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-02T00:26:22.035Z","etag":null,"topics":["aws","aws-api-gateway","aws-cdk","aws-lambda","pushover-api","terraform"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shaftoe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-01-26T18:35:19.000Z","updated_at":"2023-06-29T11:40:07.000Z","dependencies_parsed_at":"2024-01-06T10:14:58.116Z","dependency_job_id":"36304c76-8c2d-4c84-996c-8ce07a4cec55","html_url":"https://github.com/shaftoe/api-gateway-lambda-cdk-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaftoe%2Fapi-gateway-lambda-cdk-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaftoe%2Fapi-gateway-lambda-cdk-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaftoe%2Fapi-gateway-lambda-cdk-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaftoe%2Fapi-gateway-lambda-cdk-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaftoe","download_url":"https://codeload.github.com/shaftoe/api-gateway-lambda-cdk-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859027,"owners_count":16556037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-api-gateway","aws-cdk","aws-lambda","pushover-api","terraform"],"created_at":"2024-08-01T00:01:11.445Z","updated_at":"2025-10-28T18:30:44.496Z","avatar_url":"https://github.com/shaftoe.png","language":"Python","readme":"# Mini Tutorial: Setup AWS Lambda + ACM + API Gateway with AWS Cloud Development Kit (CDK)\n\nWe're going to deploy a functional public API that receives an HTML form (e.g. `/contact_us.html`) POST request and delivers its data to [Pushover][pushover] notification service.\n\nThis tutorial is based on the excellent one that you can find at \u003chttps://cdkworkshop.com/30-python.html\u003e and it resembles it closely.\n\nHere's how it differs:\n\n- bootstrapped from a real live project migration from Terraform to AWS CDK\n- shows how to integrate API Gateway and ACM to expose https endpoint under a personal domain (e.g. https://api.yourdomain.com/)\n- fully automated with `make`\n\nLinked blog post: [Introducing AWS CDK with a real life Lambda / API gateway example][linked-blogpost]\n\nOriginal blog post: [Setup a custom domain REST API endpoint on AWS Lambda: a step by step tutorial][original-blogpost]\n\n## Architecture\n\nA simple diagram of the deployed AWS resources and 3rd party service:\n\n    https://api.yourdomain.com/ \u003c---\u003e API Gateway REST proxy \u003c---\u003e AWS Lambda ---\u003e Pushover (3rd party)\n                                              |---\u003e AWS Cert Manager\n\n## Requirements\n\nBefore reading any further please ensure you've [properly installed CDK][getting-started] on your workstation.\n\nUnless you disable ACM integration commenting some code, you need to be able to verify the domain ownership of _yourdomain.com_ via email validation ([check docs][check-docs] for details).\n\n## Setup\n\n1. create a test AWS environment in your `~/.aws/credentials` file with administrator permissions, e.g.\n\n        [testing]\n        aws_access_key_id = \u003cyour-admin-key\u003e\n        aws_secret_access_key = \u003cyour-admin-secret\u003e\n        region = eu-west-1\n\n1. `git clone` this repository and `cd` into the base folder\n1. add your data to [`config.mk.example`](config.mk.example) (pay special attention to `AWS_PROFILE`) and save it to `config.mk` in the same base folder\n1. run `make all` to bootstrap the CDK project and fully provision the needed infrastructure (WARNING: check emails during deployment and validate domain ownership to speed up the process). You'll be prompted to accept the proposed changes to IAM, type `y` and `enter`. You'll also receive some emails asking you to follow a link to validate the ownership of your domain.\n\nAt this point you should have a working environment deployed and ready to be tested:\n\n        [...]\n        Outputs:\n        apitest-l3x-in.apitestl3xingatewayEndpoint70DD9352 = https://utryz8cx6g.execute-api.eu-central-1.amazonaws.com/prod/\n\n        Stack ARN:\n        arn:aws:cloudformation:eu-central-1:130728781160:stack/apitest-l3x-in/03fc9db0-4670-11ea-a198-02205d104246\n        ###########################################################################\n        # remember to add the DNS record to enable owned domain:\n        #\n        # apitest.l3x.in\tCNAME\t d-xnf9352jj8.execute-api.eu-central-1.amazonaws.com\n        ###########################################################################\n\n        $ curl -X POST https://utryz8cx6g.execute-api.eu-central-1.amazonaws.com/prod/contact_us\n        {\"error\": \"JSON body is malformatted: the JSON object must be str, bytes or bytearray, not NoneType\"}\n\nIf you see that error message it means that everything should work as expected (we get an HTTP 405 as expected because we're not passing any data in our POST).\n\nYou can add now the DNS record and (after propagation) test it with proper URL and data:\n\n        $ curl -X POST https://apitest.l3x.in/contact_us \\\n            --data '{\"name\":\"Testing the APIs\",\"email\":\"your@email.com\",\"description\":\"CDK is powerful\"}'\n        {\"message\": \"message delivered\"}\n\n## Playground\n\nYou can find the CDK implementation in the [`src`](src/) directory, Lambda source code in [`lambda/contact_us.py`](lambda/contact_us.py).\n\nThe [setup](#setup) step will place these source code files in new folders created by CDK: `api/` and `api/api`.\n\nFeel free to add and remove _constructs_ to `api/api/api_stack.py` and/or edit the Lambda in `api/lambda/contact_us.py` as you wish, executing `make deploy` will take care of checking for errors and, if none found, applying your changes (if any).\n\nAs an exercise you might think of adding an SQS service in the _stack_ to decouple the Pushover service from the main Lambda and have it in a dedicated Lambda not exposed to the public, etc.\n\n## Clean up\n\nRun `make destroy` to destroy all the resources created by CloudFormation. The only task `make` will not do for you is to remove a few of the CDK leftovers (CloudFormation CDK _meta_ stack and CloudWatch Logs generated by Lambda)\n\n[pushover]:          \u003chttps://pushover.net/\u003e\n[linked-blogpost]:   \u003chttps://a.l3x.in/2020/02/04/migrating-from-terraform-to-cdk.html\u003e\n[original-blogpost]: \u003chttps://a.l3x.in/2018/07/25/lambda-api-custom-domain-tutorial.html\u003e\n[getting-started]:   \u003chttps://docs.aws.amazon.com/cdk/latest/guide/getting_started.html\u003e\n[check-docs]:        \u003chttps://docs.aws.amazon.com/acm/latest/userguide/gs-acm-validate-email.html\u003e\n","funding_links":[],"categories":["Training Materials and Sample Code"],"sub_categories":["Multi-accounts setup"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaftoe%2Fapi-gateway-lambda-cdk-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaftoe%2Fapi-gateway-lambda-cdk-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaftoe%2Fapi-gateway-lambda-cdk-example/lists"}