Add a table viewer to your stack #
Add the following highlighted lines to
cdk_workshop_stack.py
to add a TableViewer
construct to your stack:
from constructs import Construct
from aws_cdk import (
Stack,
aws_lambda as _lambda,
aws_apigateway as apigw,
)
from cdk_dynamo_table_view import TableViewer
from .hitcounter import HitCounter
class CdkWorkshopStack(Stack):
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
# Defines an AWS Lambda resource
hello = _lambda.Function(
self, 'HelloHandler',
runtime=_lambda.Runtime.PYTHON_3_7,
code=_lambda.Code.from_asset('lambda'),
handler='hello.handler',
)
hello_with_counter = HitCounter(
self, 'HelloHitCounter',
downstream=hello,
)
apigw.LambdaRestApi(
self, 'Endpoint',
handler=hello_with_counter._handler,
)
TableViewer(
self, 'ViewHitCounter',
title='Hello Hits',
table=??????
)
What about the table? #
As you’ll notice, TableViewer
requires that you specify a table
property.
What we want is to somehow access the DynamoDB table behind our hit counter. However, the current API of our hit counter doesn’t expose the table as a public member.
In the next section, we’ll expose our table as a property of HitCounter
so we
can access it from our stack.