import os
from aws_cdk import core, aws_dynamodb, aws_lambda, aws_apigateway, aws_ecs, aws_ec2
from traffic import Traffic
from cdk_watchful import Watchful
# we need default values here since aws-cdk-examples build synthesizes the app
ACCOUNT= os.environ['CDK_DEFAULT_ACCOUNT']
REGION = os.environ['CDK_DEFAULT_REGION']
VPC_ID = os.environ.get('TESTENV_VPC_ID', 'vpc-0e3593e52a414954907aa21d32b2df894f')
AWS_ENV = core.Environment(account=ACCOUNT, region=REGION)
class UrlShortStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, env=AWS_ENV, **kwargs)
# The code that defines your stack goes here
table = aws_dynamodb.Table(self, "mapping",
partition_key = aws_dynamodb.Attribute(name="id",type=aws_dynamodb.AttributeType.STRING))
function = aws_lambda.Function(self, "backend",
runtime=aws_lambda.Runtime.PYTHON_3_7,
handler="handler.main",
code=aws_lambda.Code.asset("./lambda"))
table.grant_read_write_data(function)
function.add_environment("TABLE_NAME", table.table_name)
api = aws_apigateway.LambdaRestApi(self, "api", handler=function)
wf = Watchful(self, 'monitoring', alarm_email='scv@studydev.com')
wf.watch_scope(self)
class TrafficStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, env=AWS_ENV, **kwargs)
# lookup our pre-created VPC by ID
vpc_env = aws_ec2.Vpc.from_lookup(self, "vpc",
vpc_id=VPC_ID)
Traffic(self, 'TestTraffic',
vpc= vpc_env,
url="https://7vzqf6htub.execute-api.ap-southeast-1.amazonaws.com/prod/2a3c26e0",
tps=10)
|