(self, scope: Construct, id: str, **kwarg)
| 9 | # our main application stack |
| 10 | class UrlShortenerStack(WaltersCoStack): |
| 11 | def __init__(self, scope: Construct, id: str, **kwarg) -> None: |
| 12 | super().__init__(scope, id, **kwarg) |
| 13 | |
| 14 | # define the table that maps short codes to URLs. |
| 15 | table = aws_dynamodb.Table(self, "Table", |
| 16 | partition_key=aws_dynamodb.Attribute( |
| 17 | name="id", |
| 18 | type=aws_dynamodb.AttributeType.STRING), |
| 19 | read_capacity=10, |
| 20 | write_capacity=5) |
| 21 | |
| 22 | # define the API gateway request handler. all API requests will go to the same function. |
| 23 | handler = aws_lambda.Function(self, "UrlShortenerFunction", |
| 24 | code=aws_lambda.Code.from_asset("./lambda"), |
| 25 | handler="handler.main", |
| 26 | timeout=Duration.minutes(5), |
| 27 | runtime=aws_lambda.Runtime.PYTHON_3_7) |
| 28 | |
| 29 | # pass the table name to the handler through an environment variable and grant |
| 30 | # the handler read/write permissions on the table. |
| 31 | handler.add_environment('TABLE_NAME', table.table_name) |
| 32 | table.grant_read_write_data(handler) |
| 33 | |
| 34 | # define the API endpoint and associate the handler |
| 35 | api = aws_apigateway.LambdaRestApi(self, "UrlShortenerApi", |
| 36 | handler=handler) |
| 37 | |
| 38 | # map go.waltersco.co to this api gateway endpoint |
| 39 | # the domain name is a shared resource that can be accessed through the API in WaltersCoStack |
| 40 | # NOTE: you can comment this out if you want to bypass the domain name mapping |
| 41 | self.map_waltersco_subdomain('go', api) |
| 42 | |
| 43 | # define a Watchful monitoring system and watch the entire scope |
| 44 | # this will automatically find all watchable resources and add |
| 45 | # them to our dashboard |
| 46 | # This has been temporarily disabled while cdk_watchful is upgraded to CDKv2 |
| 47 | # wf = Watchful(self, 'watchful', alarm_email='your@email.com') |
| 48 | # wf.watch_scope(self) |
| 49 | |
| 50 | |
| 51 | # separate stack that includes the traffic generator |
no test coverage detected