-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudformation.yml
111 lines (100 loc) · 2.61 KB
/
cloudformation.yml
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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
PROJECT:
Type: String
ENVIRONMENT:
Type: String
Mappings:
dev:
api:
hostname: aws.triplehead.net
Resources:
#region REST API
ApiGateway:
Type: AWS::Serverless::Api
Properties:
Name: !Sub ${PROJECT}-${ENVIRONMENT}
StageName: !Ref ENVIRONMENT
Cors:
AllowMethods: "'POST, GET, OPTIONS'"
AllowHeaders: "'Content-Type'"
AllowOrigin: "'*'"
BasePath:
Type: AWS::ApiGateway::BasePathMapping
Properties:
BasePath: !Sub ${PROJECT}
DomainName: !FindInMap [!Ref ENVIRONMENT, api, hostname]
RestApiId: !Ref ApiGateway
Stage: !Ref ApiGateway.Stage
ApiLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${PROJECT}-api-${ENVIRONMENT}
Runtime: nodejs14.x
CodeUri: dist/src/
Handler: index.handler
MemorySize: 512
Timeout: 25
Tracing: Active
Environment:
Variables:
API_BASE_PATH: !Sub ${PROJECT}
ENVIRONMENT: !Sub ${ENVIRONMENT}
LOG_LEVEL: info
PROJECT: !Sub ${PROJECT}
TARGET_BUCKET: !Sub ${OutputBucket}
Events:
ApiEvent:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Method: post
Path: /
Policies:
- Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:PutObject
Resource:
- !Sub ${OutputBucket.Arn}
- !Sub ${OutputBucket.Arn}/*
ApiLambdaInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref ApiLambda
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
ApiHandlerLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${ApiLambda}
RetentionInDays: 60
#endregion
#region S3 bucket for PDF storage
OutputBucket:
Type: AWS::S3::Bucket
Properties:
LifecycleConfiguration:
Rules:
- Id: TTL
Status: Enabled
ExpirationInDays: 365
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html
OutputBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref OutputBucket
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: PublicReadGetObject,
Effect: Allow
Principal: '*'
Action:
- s3:GetObject
Resource: !Sub ${OutputBucket.Arn}/*
#endregion