-
Notifications
You must be signed in to change notification settings - Fork 1
/
sam-template.yaml
109 lines (97 loc) · 3.02 KB
/
sam-template.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Serverless Express Application/API powered by API Gateway and Lambda
Parameters:
DomainName:
Type: String
Description: API Domain name
Default: ''
Conditions:
UseDomainName: !Not
- !Equals
- !Ref DomainName
- ''
Resources:
ExpressApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
BinaryMediaTypes: ['*/*']
ExpressLambdaFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./dist
Handler: main.handler
MemorySize: 128
Runtime: nodejs16.x
Timeout: 30
Events:
ProxyApiRoot:
Type: Api
Properties:
RestApiId: !Ref ExpressApi
Path: /
Method: ANY
ProxyApiGreedy:
Type: Api
Properties:
RestApiId: !Ref ExpressApi
Path: /{proxy+}
Method: ANY
MyApiCertificate:
Type: 'AWS::CertificateManager::Certificate'
Condition: UseDomainName
Properties:
DomainName: !Sub '*.${DomainName}'
DomainValidationOptions:
- DomainName: !Sub '*.${DomainName}'
ValidationDomain: !Ref DomainName
SubjectAlternativeNames:
- !Ref DomainName
MyApiDomainName:
Type: 'AWS::ApiGateway::DomainName'
Condition: UseDomainName
Properties:
CertificateArn: !Ref MyApiCertificate
DomainName: !Ref DomainName
MyApiBasePathMapping:
Type: 'AWS::ApiGateway::BasePathMapping'
Condition: UseDomainName
Properties:
RestApiId: !Ref ExpressApi
DomainName: !Ref MyApiDomainName
BasePath: '(none)'
Stage: prod
Route53HostedZone:
Type: AWS::Route53::HostedZone
Condition: UseDomainName
Properties:
Name: !Ref DomainName
MyApiRoute53RecordSetGroup:
Type: AWS::Route53::RecordSetGroup
Condition: UseDomainName
Properties:
HostedZoneId: !Ref Route53HostedZone
RecordSets:
- Name: !Sub ${DomainName}.
Type: A
AliasTarget:
EvaluateTargetHealth: false
HostedZoneId: !GetAtt MyApiDomainName.DistributionHostedZoneId
DNSName: !GetAtt MyApiDomainName.DistributionDomainName
Outputs:
LambdaFunctionConsoleUrl:
Description: Console URL for the Lambda Function.
Value: !Sub https://${AWS::Region}.console.aws.amazon.com/lambda/home?region=${AWS::Region}#/functions/${ExpressLambdaFunction}
ApiGatewayApiConsoleUrl:
Description: Console URL for the API Gateway API's Stage.
Value: !Sub https://${AWS::Region}.console.aws.amazon.com/apigateway/home?region=${AWS::Region}#/apis/${ExpressApi}/stages/prod
ApiUrl:
Description:
Invoke URL for your API. Clicking this link will perform a GET request
on the root resource of your API.
Value: !Sub https://${ExpressApi}.execute-api.${AWS::Region}.amazonaws.com/prod/
LambdaFunctionName:
Description: Name of the Serverless Express Lambda Function
Value: !Ref ExpressLambdaFunction