AWS/CDK

[AWS CDK] DEFINE THE HITCOUNTER API

brightlightkim 2022. 3. 29. 05:22

Create a new file for our hit counter construct

Create a new file under lib called hitcounter.ts with the following content:

import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';

export interface HitCounterProps {
  /** the function for which we want to count url hits **/
  downstream: lambda.IFunction;
}

export class HitCounter extends Construct {
  constructor(scope: Construct, id: string, props: HitCounterProps) {
    super(scope, id);

    // TODO
  }
}

Save the file. Oops, an error! No worries, we’ll be using props shortly.

What’s going on here?

  • We declared a new construct class called HitCounter.
  • As usual, constructor arguments are scope, id and props, and we propagate them to the cdk.Construct base class.
  • The props argument is of type HitCounterProps which includes a single property downstream of type lambda.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.

'AWS > CDK' 카테고리의 다른 글

[AWS CDK] DEFINE RESOURCES  (0) 2022.03.29
[AWS CDK] HIT COUNTER HANDLER  (0) 2022.03.29
[AWS CDK] Writing Constructs  (0) 2022.03.29
[AWS CDK] API GATEWAY  (0) 2022.03.29
[AWS CDK] CDK WATCH  (0) 2022.03.29