-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
executable file
·114 lines (107 loc) · 2.78 KB
/
template.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
112
113
114
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Serverless VPC Page
Parameters:
ApplicationName:
Type: String
Default: 'ServerlessVPCPage'
FrontPageApiStageName:
Type: String
Default: 'ProdStage'
VpcCidrBlock:
Type: String
Default: '192.168.2.0/24'
VpcName:
Type: String
Default: "SampleVPC"
AZ:
Type: AWS::EC2::AvailabilityZone::Name
Default: "ap-northeast-1a"
PublicSubnetCidrBlock:
Type: String
Default: '192.168.2.0/25'
PublicSubnetName:
Type: String
Default: "SamplePublicSubnet"
Resources:
FrontPageApi:
Type: AWS::Serverless::Api
Properties:
Name: ServerlessVPCPageApi
EndpointConfiguration: REGIONAL
StageName: !Ref FrontPageApiStageName
FrontPageFunction:
Type: AWS::Serverless::Function
Properties:
Architectures:
- arm64
FunctionName: ServerlessVPCPageFrontFunction
CodeUri: bin/
Handler: bootstrap
MemorySize: 256
Runtime: provided.al2
Description: 'VPC Front Function'
Environment:
Variables:
REGION: !Ref 'AWS::Region'
API_PATH: !Join [ '', [ '/', !Ref FrontPageApiStageName, '/api'] ]
Events:
FrontPageApi:
Type: Api
Properties:
Path: '/'
Method: get
RestApiId: !Ref FrontPageApi
MainFunction:
Type: AWS::Serverless::Function
Properties:
Architectures:
- arm64
FunctionName: ServerlessVPCPageMainFunction
CodeUri: api/bin/
Handler: bootstrap
MemorySize: 256
Runtime: provided.al2
Description: 'VPC API Function'
Policies:
- Statement:
- Effect: 'Allow'
Action:
- 'ec2:Describe*'
Resource: '*'
Environment:
Variables:
REGION: !Ref 'AWS::Region'
VPC_ID: !Ref SampleVPC
SUBNET_ID: !Ref SamplePublicSubnet
Events:
FrontPageApi:
Type: Api
Properties:
Path: '/api'
Method: post
RestApiId: !Ref FrontPageApi
SampleVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCidrBlock
EnableDnsHostnames: true
EnableDnsSupport: true
InstanceTenancy: default
Tags:
- Key: Name
Value: !Ref VpcName
SamplePublicSubnet:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Ref AZ
CidrBlock: !Ref PublicSubnetCidrBlock
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Ref PublicSubnetName
VpcId: !Ref SampleVPC
Outputs:
APIURI:
Description: "URI"
Value: !Join [ '', [ 'https://', !Ref FrontPageApi, '.execute-api.',!Ref 'AWS::Region','.amazonaws.com/',!Ref FrontPageApiStageName,'/'] ]