-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yaml
83 lines (79 loc) · 2.71 KB
/
serverless.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
service: lambda-function-url-custom-domain
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs14.x
region: ${opt:region, 'eu-west-1'}
lambdaHashingVersion: '20201221'
custom:
apiDomain: api.example.com # change by your custom domain
hostedZoneName: example.com. # your domain Route 53 hosted zone name
certificateNVirginaArn: arn:aws:acm:us-east-1:xxxxxx:certificate/xxxxxxx # change by your certificate ARN (should be in North Virginia region)
functions:
api:
handler: lambda.handler
url: true # needed to expose lambda function url !
resources:
Resources:
ApiCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
DeletionPolicy: Delete
Properties:
DistributionConfig:
Enabled: true
PriceClass: PriceClass_100
HttpVersion: http2
Comment: Api distribution for ${self:custom.apiDomain}
Origins:
- Id: ApiGateway
DomainName: !Select [2, !Split ["/", !GetAtt ApiLambdaFunctionUrl.FunctionUrl]] # extract function url form your lambda resource
OriginPath: ''
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: https-only
OriginSSLProtocols: [TLSv1, TLSv1.1, TLSv1.2]
DefaultCacheBehavior:
TargetOriginId: ApiGateway
ViewerProtocolPolicy: redirect-to-https
Compress: true
DefaultTTL: 0
AllowedMethods:
- HEAD
- DELETE
- POST
- GET
- OPTIONS
- PUT
- PATCH
CachedMethods:
- HEAD
- OPTIONS
- GET
ForwardedValues:
QueryString: false
Headers:
- Accept
- x-api-key
- Authorization
Cookies:
Forward: none
Aliases:
- ${self:custom.apiDomain}
ViewerCertificate:
SslSupportMethod: sni-only
MinimumProtocolVersion: TLSv1.2_2019
AcmCertificateArn: ${self:custom.certificateNVirginaArn}
ApiRecordSetGroup:
Type: AWS::Route53::RecordSetGroup
DeletionPolicy: Delete
DependsOn:
- ApiCloudFrontDistribution
Properties:
HostedZoneName: ${self:custom.hostedZoneName}
RecordSets:
- Name: ${self:custom.apiDomain}
Type: A
AliasTarget:
HostedZoneId: Z2FDTNDATAQYW2 # Cloudfront default hosted zone ID
DNSName: { 'Fn::GetAtt': [ApiCloudFrontDistribution, DomainName] } # set the domain of your cloudfront distribution