export async function handleCreate()

in source/presentation-configurer/source/index.ts [13:67]


export async function handleCreate(props: IResourceProperties): Promise<CompletionStatus> {
  const s3 = new AWS.S3();

  // get file manifest from s3
  const getManifestParams = {
    Bucket: props.SrcBucket,
    Key: `${props.SrcPath}/${props.ManifestFile}`
  };

  const data = await s3.getObject(getManifestParams).promise();
  const manifest: string[] = JSON.parse(data.Body.toString());
  console.log('Manifest:', JSON.stringify(manifest, null, 2));

  // Loop through manifest and copy files to the destination buckets
  await Promise.all(manifest.map(async (file) => {
    let params = {
      Bucket: props.ConsoleBucket,
      CopySource: `${props.SrcBucket}/${props.SrcPath}/${file}`,
      Key: file
    };

    console.log(`Copying: ${JSON.stringify(params)}`);
    let resp = await s3.copyObject(params).promise();
    console.log('file copied to s3: ', resp);
  }));

  await s3.putObject({
    Bucket: props.ConsoleBucket,
    Key: 'console/uiConfig.json',
    Body: Buffer.from(JSON.stringify({
      identityPoolId: props.IdentityPoolId,
      userPoolClientId: props.UserPoolClientId,
      userPoolId: props.UserPoolId,
      uiRegion: props.UIRegion,
      primary: {
        stateUrl: `${props.PrimaryRoutingLayerEndpoint}/state/${props.AppId}`,
        objectStoreBucketName: props.PrimaryObjectStoreBucket,
        photosApi: props.PrimaryPhotosApiEndpoint,
        region: props.PrimaryRegion
      },
      secondary: {
        stateUrl: `${props.SecondaryRoutingLayerEndpoint}/state/${props.AppId}`,
        objectStoreBucketName: props.SecondaryObjectStoreBucket,
        photosApi: props.SecondaryPhotosApiEndpoint,
        region: props.SecondaryRegion
      }
    }))
  }).promise();
  console.log('Successfully wrote uiConfig.json');

  return Promise.resolve({
    Status: StatusTypes.Success,
    Data: { Message: 'Successfully configured Demo UI' }
  });
}