libフォルダ配下に次のようなhitcounter.tsファイルを作成します。
import { IFunction } from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
export interface HitCounterProps {
/** the function for which we want to count url hits **/
downstream: IFunction;
}
export class HitCounter extends Construct {
constructor(scope: Construct, id: string, props: HitCounterProps) {
super(scope, id);
// TODO
}
}
ファイルを保存すると、エラーが発生しますが心配いりません。 この後すぐに props プロパティを追加します。
HitCounterという名前のコンストラクトクラスを新しく定義しています。scope, id, props のコンストラクター引数を設定し、基底クラスである Construct に伝搬させます。propsは、IFunction型のdownstream というプロパティを含む、HitCounterProps型の引数です。
前の章で作成したLambda関数をここに接続して、HitCountが機能するようにします。次に、HitCounterのハンドラーコードを記述します。