Create a new file for our hit counter construct #
Create a new file under cdk_workshop
called hitcounter.py
with the following content:
from constructs import Construct
from aws_cdk import (
aws_lambda as _lambda,
)
class HitCounter(Construct):
def __init__(self, scope: Construct, id: str, downstream: _lambda.IFunction, **kwargs):
super().__init__(scope, id, **kwargs)
# TODO
Save the file.
What’s going on here? #
- We declared a new construct class called
HitCounter
. - As usual, constructor arguments are
scope
,id
andkwargs
, and we propagate them to thecdk.Construct
base class. - The
HitCounter
class also takes one explicit keyword parameterdownstream
of typelambda.IFunction
. This is where we are going to “plug in” the Lambda function we created in the previous chapter so it can be hit-counted.
Next, we are going to write the handler code of our hit counter.