constructor()

in source/5-unicornPics/backend/lib/frontend/frontend-config.ts [16:59]


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

    this.config = JSON.stringify({
      Auth: {
        region: cdk.Stack.of(props.auth).region,
        userPoolId: props.auth.userPool.userPoolId,
        userPoolWebClientId: props.auth.userPoolClient.userPoolClientId,
      },
      API: {
        endpoints: [
          {
            name: props.postService.postsApi.restApiName,
            endpoint: props.postService.postsApi.url,
          },
        ],
      },
      Analytics: {
        disabled: true,
      },
    });

    const configDeployment = new cr.AwsCustomResource(this, 'WriteS3ConfigFile', {
      onUpdate: {
        service: 'S3',
        action: 'putObject',
        parameters: {
          Body: this.config,
          Bucket: props.frontend.activateBucket.bucketName,
          Key: 'config.json',
        },
        physicalResourceId: cr.PhysicalResourceId.of(Date.now().toString()), // always write this file
      },
      policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
        resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
      }),
    });

    configDeployment.node.addDependency(props.frontend.siteDeployment);

    new cdk.CfnOutput(this, 'frontendConfig', {
        value: this.config
    });
  }