Last active
March 4, 2021 07:33
-
-
Save apoorvmote/1a653acfb77ec11771e904089c4c8dc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new ARecord(this, 'apiAliasRecord', { | |
zone: hostedZone, | |
target: RecordTarget.fromAlias(new ApiGatewayv2Domain(domain)) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hostedZone = HostedZone.fromHostedZoneAttributes(this, 'hostedZoneWithAttributes', { | |
hostedZoneId, | |
zoneName: website_domain | |
}) | |
const apiCert = new DnsValidatedCertificate(this, 'ApiSSL', { | |
domainName: api_domain, | |
hostedZone | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const existingAPI = HttpApi.fromHttpApiAttributes(this, 'existingAPI', { | |
apiEndpoint: api_domain, | |
httpApiId: 'myApiId' | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const domain = new DomainName(this, 'api_domain', { | |
domainName: api_domain, | |
certificate: apiCert | |
}) | |
const api = new HttpApi(this, 'apiEndpoint', { | |
defaultDomainMapping: { | |
domainName: domain | |
}, | |
corsPreflight: { | |
allowCredentials: true, | |
allowHeaders: ['Content-Type'], | |
allowMethods: [HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE], | |
allowOrigins: [ | |
'https://example.com' | |
] | |
}, | |
apiName: 'exampleAPI', | |
disableExecuteApiEndpoint: true | |
}) | |
new CfnOutput(this, 'apiID', { | |
value: api.httpApiId | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////// | |
// Part 1 | |
const hostedZone = HostedZone.fromHostedZoneAttributes(this, 'hostedZoneWithAttributes', { | |
hostedZoneId, | |
zoneName: website_domain | |
}) | |
const certificate = new DnsValidatedCertificate(this, 'ApiSSL', { | |
domainName: website_domain, | |
hostedZone | |
}) | |
const api = new HttpApi(this, 'apiEndpoint', { | |
apiName: 'exampleAPISameDomain', | |
}) | |
new CfnOutput(this, 'apiID', { | |
value: api.apiEndpoint | |
}) | |
const signUpFn = new Function(this, 'signUpFn', { | |
runtime: Runtime.NODEJS_14_X, | |
code: Code.fromAsset(`${__dirname}/../lambda-fns/sign-up/deployment.zip`), | |
handler: 'index.handler', | |
memorySize: 512 | |
}) | |
/////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////// | |
// Part 2 | |
api.addRoutes({ | |
path: '/api/sign-up', | |
methods: [HttpMethod.POST], | |
integration: new LambdaProxyIntegration({ handler: signUpFn }) | |
}) | |
const apiOriginPolicy = new OriginRequestPolicy(this, 'apiOriginPolicy', { | |
cookieBehavior: OriginRequestCookieBehavior.all(), | |
headerBehavior: OriginRequestHeaderBehavior.none(), | |
queryStringBehavior: OriginRequestQueryStringBehavior.all() | |
}) | |
const distribution = new Distribution(this, 'websiteAndAPIDistribution', { | |
defaultBehavior: { | |
origin: new HttpOrigin('origin-source-code.com'), | |
}, | |
additionalBehaviors: { | |
'api/*': { | |
origin: new HttpOrigin(api.apiEndpoint.replace('https://', '')), | |
allowedMethods: AllowedMethods.ALLOW_ALL, | |
cachePolicy: CachePolicy.CACHING_DISABLED, | |
compress: false, | |
originRequestPolicy: apiOriginPolicy, | |
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS | |
} | |
}, | |
domainNames: [website_domain], | |
certificate, | |
minimumProtocolVersion: SecurityPolicyProtocol.TLS_V1_2_2019, | |
enableIpv6: true, | |
enabled: true, | |
httpVersion: HttpVersion.HTTP2, | |
priceClass: PriceClass.PRICE_CLASS_ALL | |
}) | |
/////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////// | |
// Part 3 | |
new ARecord(this, 'AliasForCloudfront', { | |
target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)), | |
zone: hostedZone, | |
recordName: website_domain | |
}) | |
/////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const signUpFn = new Function(this, 'signUpFn', { | |
runtime: Runtime.NODEJS_14_X, | |
code: Code.fromAsset(`${__dirname}/../lambda-fns/sign-up/deployment.zip`), | |
handler: 'index.handler', | |
memorySize: 512 | |
}) | |
api.addRoutes({ | |
path: '/sign-up', | |
methods: [HttpMethod.POST], | |
integration: new LambdaProxyIntegration({ handler: signUpFn }) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////// | |
// Part 1 | |
const hostedZone = HostedZone.fromHostedZoneAttributes(this, 'hostedZoneWithAttributes', { | |
hostedZoneId, | |
zoneName: website_domain | |
}) | |
const apiCert = new DnsValidatedCertificate(this, 'ApiSSL', { | |
domainName: api_domain, | |
hostedZone | |
}) | |
/////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////// | |
// Part 2 | |
const domain = new DomainName(this, 'api_domain', { | |
domainName: api_domain, | |
certificate: apiCert | |
}) | |
const api = new HttpApi(this, 'apiEndpoint', { | |
defaultDomainMapping: { | |
domainName: domain | |
}, | |
corsPreflight: { | |
allowCredentials: true, | |
allowHeaders: ['Content-Type'], | |
allowMethods: [HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE], | |
allowOrigins: [ | |
'https://example.com' | |
] | |
}, | |
apiName: 'exampleAPI', | |
disableExecuteApiEndpoint: true | |
}) | |
new CfnOutput(this, 'apiID', { | |
value: api.httpApiId | |
}) | |
const signUpFn = new Function(this, 'signUpFn', { | |
runtime: Runtime.NODEJS_14_X, | |
code: Code.fromAsset(`${__dirname}/../lambda-fns/sign-up/deployment.zip`), | |
handler: 'index.handler', | |
memorySize: 512 | |
}) | |
/////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////// | |
// Part 3 | |
new ARecord(this, 'apiAliasRecord', { | |
zone: hostedZone, | |
target: RecordTarget.fromAlias(new ApiGatewayv2Domain(domain)) | |
}) | |
api.addRoutes({ | |
path: '/sign-up', | |
methods: [HttpMethod.POST], | |
integration: new LambdaProxyIntegration({ handler: signUpFn }) | |
}) | |
/////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment