(Section 11 of Course: AWS & Typescript Masterclass - CDK, Serverless, React) 94-97
(95) Deployment to S3 and Cloudfront
// create bucket
this.deploymentBucket = new Bucket(
this.stack,
'space-app-web-id', {
bucketName: bucketName,
publicReadAccess: true,
websiteIndexDocument: 'index.html'
}
);
new CfnOutput(this.stack, 'spaceFinderWebAppS3Url', {
value: this.deploymentBucket.bucketWebsiteUrl
});
// upload build folder to the bucket
new BucketDeployment(
this.stack,
'space-app-web-id-deployment', {
destinationBucket: this.deploymentBucket,
sources: [
Source.asset(
join(__dirname, '..', '..', 'space-finder-frontend', 'build')
)
]
}
);
// cloudfront
const cloudFront = new CloudFrontWebDistribution(
this.stack,
'space-app-web-destribution', {
originConfigs:[
{
behaviors: [{isDefaultBehavior: true}],
s3OriginSource: {s3BucketSource: this.deploymentBucket}
}
]
}
);
new CfnOutput(this.stack, 'spaceFinderWebAppCloudFrontUrl', {
value: cloudFront.distributionDomainName
})
-> bucket does not require https ?? can a public bucket handle https?
?? does the bucket still need to be public, if it’s going through CloudFront anyway? -> cloudfront has https
(97) Exploring the finished app https://github.com/barosanuemailtest/space-finder-backend.git https://github.com/barosanuemailtest/space-finder-frontend.git
API integration with CORS
const optionsWithCors: ResourceOptions = {
defaultCorsPreflightOptions: {
allowOrigins: Cors.ALL_ORIGINS,
allowMethods: Cors.ALL_METHODS,
}
}
const spaceResource = this.api.root.addResource('spaces', optionsWithCors);
spaceResource.addMethod('POST', this.spacesTable.createLambdaIntegration, optionsWithAuthorizer);
...
?? did this move out of the lambdas?
- no
?? is the one in the lambda now redundant?
- todo: find out