-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
109 lines (95 loc) · 2.9 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-cors1
Sample SAM Template for sam-cors1
Parameters:
BucketName:
Type: String
Default: www-cors1
StageName:
Type: String
Default: Prod
Globals:
Function:
Timeout: 3
Api:
OpenApiVersion: 3.0.3
Resources:
Cors1ApiGw:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref StageName
# Auth:
# Authorizer: 'NONE'
Cors:
AllowOrigin: "'*'"
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
AllowMethods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
# AllowCredentials: true 'AllowOrigin' is "'*'"だと設定できない
HelloFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello/
Handler: app.lambda_handler
Runtime: python3.8
Environment:
Variables:
CorsDomain: !Sub "https://s3-${AWS::Region}.amazonaws.com"
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
RestApiId: !Ref Cors1ApiGw
HelloFunctionLogGroup:
Type: AWS::Logs::LogGroup
DependsOn: HelloFunction
Properties:
RetentionInDays: 7
LogGroupName: !Join ["", ["/aws/lambda/", !Ref HelloFunction]]
GoodbyeFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello/ # helloと共用
Handler: app.lambda_handler
Runtime: python3.8
Events:
GoodbyeWorld:
Type: Api
Properties:
Path: /goodbye
Method: get
RestApiId: !Ref Cors1ApiGw
GoodbyeFunctionLogGroup:
Type: AWS::Logs::LogGroup
DependsOn: GoodbyeFunction
Properties:
RetentionInDays: 7
LogGroupName: !Join ["", ["/aws/lambda/", !Ref GoodbyeFunction]]
# テスト用WWWの置き場所
S3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
BucketName: !Ref BucketName
MetricsConfigurations:
- Id: EntireBucket
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: error.html
DeletionPolicy: Delete
Outputs:
HelloApiURL:
Description: "API Gateway endpoint URL for Prod stage for Hello function"
Value: !Sub "https://${Cors1ApiGw}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/hello/"
GoodbyeApiURL:
Description: "API Gateway endpoint URL for Prod stage for Goodbye function"
Value: !Sub "https://${Cors1ApiGw}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/goodbye/"
S3URL:
Description: URL of S3 bucket to hold website content
Value: !Sub "http://${S3Bucket}.s3-website-${AWS::Region}.amazonaws.com/"
S3SecureURL:
Description: Secure URL of S3 bucket to hold website content
Value: !Sub "https://s3-${AWS::Region}.amazonaws.com/${S3Bucket}/index.html"