--- /home/vignesh/github/Tiproemail/aws_cdk/lib/betasupplier-site-stack.ts +++ /home/vignesh/github/Tiproemail/aws_cdk/lib/betasupplier-site-stack.ts @@ -19,13 +19,25 @@ + const ec2Origin = new origins.HttpOrigin('ec2-16-113-57-127.ap-south-2.compute.amazonaws.com', { + protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY, + }); + // 2. Create CloudFront Distribution // origins.S3Origin will automatically create an Origin Access Identity (OAI) // and update the S3 bucket policy to allow access only from this CloudFront distribution. const distribution = new cloudfront.Distribution(this, 'BetaSupplierSiteDistribution', { defaultRootObject: 'index.html', defaultBehavior: { origin: new origins.S3Origin(websiteBucket), viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD, cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD, cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED, }, + additionalBehaviors: { + '/api/*': { + origin: ec2Origin, + viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, + allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, + cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED, + originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER, + } + }, errorResponses: [