-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
112 lines (98 loc) · 2.88 KB
/
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
110
111
112
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: ServerlessOps.io Site redirect
Parameters:
Domain:
Type: String
Description: 'Application Platform'
System:
Type: String
Description: 'Application System'
Component:
Type: String
Description: 'Application Component'
CodeBranch:
Type: String
Description: "Name of deployment branch"
Hostname:
Type: String
Description: Site FQDN
RedirectHostname:
Type: String
Description: Redirect site hostname
DnsZoneId:
Type: AWS::SSM::Parameter::Value<String>
Description: Route53 Hosted Zone ID
Globals:
Function:
Runtime: nodejs20.x
Timeout: 5
MemorySize: 128
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: !Ref AWS::StackName
Resources:
RedirectFunction:
Type: AWS::Serverless::Function
Properties:
Description: URL redirect function
CodeUri: ./dist/handlers/Redirect
Handler: function.handler
Environment:
Variables:
REDIRECT_HOST: !Sub "https://${RedirectHostname}"
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: "es2020"
Format: "esm"
MainFields: module,main # This is to help with ESM modules
OutExtension:
- .js=.mjs
EntryPoints:
- function.js
RedirectFunctionnInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt RedirectFunction.Arn
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
# APIG
SiteCertificate:
Type: AWS::CertificateManager::Certificate
Properties:
DomainName: !Ref Hostname
ValidationMethod: DNS
DomainValidationOptions:
- DomainName: !Ref Hostname
HostedZoneId: !Ref DnsZoneId
RestApiLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/api-gateway/${AWS::StackName}"
RetentionInDays: 7
RestApi:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref CodeBranch
Domain:
DomainName: !Ref Hostname
CertificateArn: !Ref SiteCertificate
Route53:
HostedZoneId: !Ref DnsZoneId
EndpointConfiguration: EDGE
AccessLogSetting:
DestinationArn: !GetAtt RestApiLogGroup.Arn
Format: '$context.extendedRequestId $context.identity.sourceIp $context.identity.caller $context.identity.user [$context.requestTime] "$context.httpMethod $context.resourcePath $context.protocol" $context.status $context.responseLength $context.requestId'
MethodSettings:
- ResourcePath: "/*"
HttpMethod: "*"
LoggingLevel: INFO
MetricsEnabled: true
DataTraceEnabled: false
DefinitionBody:
Fn::Transform:
Name: "AWS::Include"
Parameters:
Location: "openapi.yaml"