Skip to content

Commit 4ac3de7

Browse files
committed
initial commit
1 parent 0e4cdfa commit 4ac3de7

File tree

5 files changed

+2835
-0
lines changed

5 files changed

+2835
-0
lines changed

Diff for: .gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
.serverless/
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
pnpm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# OS
16+
.DS_Store
17+
18+
# Tests
19+
/coverage
20+
/.nyc_output
21+
22+
# IDEs and editors
23+
/.idea
24+
.project
25+
.classpath
26+
.c9/
27+
*.launch
28+
.settings/
29+
*.sublime-workspace
30+
31+
# IDE - VSCode
32+
.vscode/*
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
!.vscode/launch.json
36+
!.vscode/extensions.json
37+
38+
# Env
39+
.env*

Diff for: lambda.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
exports.handler = async (event) => {
2+
return {
3+
statusCode: 200,
4+
body: JSON.stringify('Hello from Lambda Function Url !'),
5+
};
6+
};

Diff for: package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "lambda-function-url-custom-domain",
3+
"version": "1.0.0",
4+
"main": "lambda.js",
5+
"author": "Walid KARRAY",
6+
"license": "MIT",
7+
"scripts": {
8+
"sls": "sls",
9+
"deploy": "sls deploy"
10+
},
11+
"dependencies": {},
12+
"devDependencies": {
13+
"serverless": "^3.16.0"
14+
}
15+
}

Diff for: serverless.yaml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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

Comments
 (0)