constructor()

in sandbox/CWMetricStreamExporter/cdk/lib/cdk-stack.ts [16:62]


  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const INPUT_YAML_FILE = "config.yaml"; 

    const data = convertYamlToJson(INPUT_YAML_FILE, "/../../") as any;

    const lambdaFunction = new lambda.Function(this, "KinesisStreamFunction", {
      code: lambda.Code.fromAsset("../lambda"),
      handler: "main",
      functionName: "KinesisMessageHandler",
      runtime: lambda.Runtime.GO_1_X,
      environment: {
        PROMETHEUS_REMOTE_WRITE_URL: data.AMP.remote_write_url,
        PROMETHEUS_REGION: data.AMP.region,
      },
    });

    lambdaFunction.role?.addManagedPolicy(
      iam.ManagedPolicy.fromAwsManagedPolicyName(
        "AmazonPrometheusRemoteWriteAccess"
      )
    );

    const lambdaProcessor = new LambdaFunctionProcessor(lambdaFunction, {
      bufferInterval: cdk.Duration.minutes(1),
      bufferSize: cdk.Size.mebibytes(3),
      retries: 5,
    });

    const bucket = new s3.Bucket(this, data.S3?.s3_bucket_name ?? "Bucket", {
      encryption: s3.BucketEncryption.KMS_MANAGED,
    });
    const destination = new destinations.S3Bucket(bucket, {
      processor: lambdaProcessor,
      s3Backup: {
        bucket: bucket,
      },
    });
    new DeliveryStream(
      this,
      data.Kinesis_Firehose?.delivery_stream_name ?? "Delivery Stream",
      {
        destinations: [destination],
      }
    );
  }