from aws_cdk import core, aws_dynamodb, aws_lambda, aws_apigateway, aws_
from testenvtraffic import TestEnvStackTraffic
from traffic import Trafficos
from cdk_watchful import Watchful
class UrlShortStack(TestEnvStack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id# 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-0e680e107cb16f0c9')
AWS_ENV = Environment(account=ACCOUNT, region=REGION)
class UrlShortStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
# The code that defines your stack goes here
table = aws_dynamodb.Table(self, "mapping-table",
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='meelong0@studydevscv@studydev.com')
wf.watch_scope(self)
class TrafficStack(TestEnvStackcore.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
Traffic(self, 'TestTraffic',
# lookup our pre-created VPC by ID
vpc_env = self.testenv_vpc,
url=aws_ec2.Vpc.from_lookup(self, "vpc", vpc_id=VPC_ID)
# lookup our pre-created VPC by ID
test_url = 'https://cdk.awsdemokr.com/715a930b',
Traffic(self, 'TestTraffic', vpc= vpc_env, url=test_url, tps=10)
|