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