constructor()

in cdk/lib/api-stack.ts [22:63]


  constructor(scope: Construct, id: string, props: LambdaStackProps) {
    super(scope, id, props);

    const dbPwdSecret = Secret.fromSecretNameV2(this, "dbPwdSecret", props.rdsPasswordSecretName);
    const handler = new Function(this, "graphql", {
      runtime: Runtime.NODEJS_14_X,
      code: Code.fromAsset("api"),
      handler: "build/src/graphql.handler",
      vpc: props.vpc,
      vpcSubnets: {
        subnetType: SubnetType.ISOLATED,
      },
      securityGroup: SecurityGroup.fromSecurityGroupId(
        this,
        "inboundDbAccessSecurityGroup" + "rdsLambda",
        props.inboundDbAccessSecurityGroup
      ),
      environment: {
        TYPEORM_USERNAME: props.rdsDbUser,
        TYPEORM_HOST: props.rdsEndpoint,
        TYPEORM_DATABASE: props.rdsDbName,
        TYPEORM_PORT: props.rdsPort.toString(),
        TYPEORM_PASSWORD: dbPwdSecret.secretValue.toString(),
        TYPEORM_SYNCHRONIZE: "true",
        TYPEORM_LOGGING: "true",
        TYPEORM_ENTITIES: "./build/src/entity/*.entity.js",
      },
    });

    const api = new LambdaRestApi(this, "graphql-api", {
      handler,
      proxy: false,
    });

    const graphql = api.root.addResource("graphql");
    graphql.addMethod("ANY");

    this.apiPathOutput = new CfnOutput(this, "apiPath", {
      value: api.root.path,
      description: "Path of the API"
    });
  }