constructor()

in source/use_cases/aws-serverless-web-app/lib/serverless-backend-stack.ts [25:92]


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

    const websiteBucketName: string = Fn.importValue('websiteBucket');

    const construct = new CognitoToApiGatewayToLambda(this, 'CognitoToApiGatewayToLambda', {
      lambdaFunctionProps: {
        code: lambda.Code.fromAsset(`${__dirname}/lambda/business-logic`),
        runtime: lambda.Runtime.NODEJS_14_X,
        handler: 'index.handler'
      },
      cognitoUserPoolProps: {
        userPoolName: 'WileRydes',
        userVerification: {},
        autoVerify: {
          email: true
        },
        selfSignUpEnabled: true
      },
      apiGatewayProps: {
        defaultCorsPreflightOptions: {
          allowOrigins: Cors.ALL_ORIGINS,
          allowMethods: Cors.ALL_METHODS
        }
      }
    });

    const lambdaFunc = new lambda.Function(this, 'updateConfigHandler', {
      runtime: lambda.Runtime.PYTHON_3_8,
      handler: 'update_s3_object.on_event',
      code: lambda.Code.fromAsset(`${__dirname}/lambda/cognito-config`),
      timeout: Duration.minutes(5),
      initialPolicy: [
        new PolicyStatement({
          actions: ["s3:PutObject",
                    "s3:PutObjectAcl",
                    "s3:PutObjectVersionAcl"],
          resources: [`arn:${Aws.PARTITION}:s3:::${websiteBucketName}/*`]
        }),
      ]
    });

    const customResourceProvider = new Provider(this, 'CustomResourceProvider', {
      onEventHandler: lambdaFunc
    });

    new CustomResource(this, 'CustomResource', {
      provider: customResourceProvider,
      properties: {
        UserPool: construct.userPool.userPoolId,
        Client: construct.userPoolClient.userPoolClientId,
        Region: Stack.of(this).region,
        Bucket: websiteBucketName,
        RestApi: construct.apiGateway.url
      }
    });

    new LambdaToDynamoDB(this, 'LambdaToDynamoDB', {
      existingLambdaObj: construct.lambdaFunction,
      dynamoTableProps: {
        tableName: 'Rides',
        partitionKey: {
            name: 'RideId',
            type: AttributeType.STRING
        }
      }
    });
  }