Exemple of building a Multi-region Serverless Application with Amazon API Gateway, AWS Lambda, DynamoDB Global tables, Route53 health-checks and infrastructure as code (CDK).
This is work in progress and currently assumes the DNS domain is iulianm.dev.
The stack would create ApiGateway+ACM+Lambda in us-east-1 and us-west-2.
Each region would have the following APIGateway custom domains:
api.iulianm.devapi.<region>.iulianm.dev
This guide makes use of SIGV4A which is an extension that enables signatures that are valid in more than one AWS Region.
This is a blank project for TypeScript development with CDK.
The cdk.json file tells the CDK Toolkit how to execute your app.
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testscdk deploydeploy this stack to your default AWS account/regioncdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation template
cdk synthcdk deploy DnsStackcdk deploy MultiRegionWithApigwLambdaDdbStack-PDXcdk deploy MultiRegionWithApigwLambdaDdbStack-IADGot to client directory.
pip install -r requirements.txt
Start ipython:
import requests
from sigv4a_sign import SigV4ASign
service = 'execute-api'
region = '*'
method = 'GET'
url = 'https://api.iulianm.dev'
def make_call():
headers = SigV4ASign().get_headers_basic(service, region, method, url)
r = requests.get(url, headers=headers)
return r
print(f'status_code: {make_call().status_code} \nobject text: {make_call().text}')Output:
print(f'status_code: {make_call().status_code} \nobject text: {make_call().text}')
status_code: 200
object text: {"Region ": "us-west-2"}
print(f'status_code: {make_call().status_code} \nobject text: {make_call().text}')
status_code: 200
object text: {"Region ": "us-east-1"}
