-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathcompanion-stack.yaml
More file actions
179 lines (166 loc) · 4.72 KB
/
companion-stack.yaml
File metadata and controls
179 lines (166 loc) · 4.72 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Resources:
PreCreatedVpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
PreCreatedSubnetOne:
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: PreCreatedVpc
CidrBlock: 10.0.0.0/24
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: ''
PreCreatedSubnetTwo:
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: PreCreatedVpc
CidrBlock: 10.0.1.0/24
AvailabilityZone:
Fn::Select:
- 1
- Fn::GetAZs: ''
PreCreatedInternetGateway:
Type: AWS::EC2::InternetGateway
PreCreatedAttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId:
Ref: PreCreatedVpc
InternetGatewayId:
Ref: PreCreatedInternetGateway
PreCreatedS3Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
LMIKMSKey:
Type: AWS::KMS::Key
Properties:
Description: KMS Key for Lambda Capacity Provider Resource
KeyPolicy:
Version: '2012-10-17'
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:root"
Action: kms:*
Resource: '*'
- Sid: Allow Lambda service
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action:
- kms:Decrypt
- kms:DescribeKey
Resource: '*' # Lambda Managed Instances (LMI) VPC Resources
LMIVpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-VPC"
LMIPrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref LMIVpc
CidrBlock: 10.0.1.0/24
AvailabilityZone: !Select [0, !GetAZs '']
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-PrivateSubnet"
LMIPrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref LMIVpc
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-PrivateRT"
LMIPrivateSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref LMIPrivateSubnet
RouteTableId: !Ref LMIPrivateRouteTable
LMISecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for capacity provider Lambda functions
VpcId: !Ref LMIVpc
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 10.0.0.0/16
Description: Allow HTTPS within VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-LambdaSG"
VPCEndpointSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for VPC endpoints
VpcId: !Ref LMIVpc
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 10.0.0.0/16
Description: Allow HTTPS from within VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-VPCEndpointSG"
CloudWatchLogsEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcId: !Ref LMIVpc
ServiceName: !Sub 'com.amazonaws.${AWS::Region}.logs'
VpcEndpointType: Interface
PrivateDnsEnabled: true
SubnetIds:
- !Ref LMIPrivateSubnet
SecurityGroupIds:
- !Ref VPCEndpointSecurityGroup
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-CloudWatchLogsEndpoint"
Outputs:
PreCreatedVpc:
Description: Pre-created VPC that can be used inside other tests
Value:
Ref: PreCreatedVpc
PreCreatedSubnetTwo:
Description: 'Pre-created #2 subnet that can be used inside other tests'
Value:
Ref: PreCreatedSubnetTwo
PreCreatedSubnetOne:
Description: 'Pre-created #1 subnet that can be used inside other tests'
Value:
Ref: PreCreatedSubnetOne
PreCreatedInternetGateway:
Description: Pre-created Internet Gateway that can be used inside other tests
Value:
Ref: PreCreatedInternetGateway
PreCreatedAttachGateway:
Description: Pre-created Attach Gateway that can be used inside other tests
Value:
Ref: PreCreatedAttachGateway
PreCreatedS3Bucket:
Description: Pre-created S3 Bucket that can be used inside other tests
Value:
Ref: PreCreatedS3Bucket
LMISubnetId:
Description: Private subnet ID for Lambda functions
Value: !Ref LMIPrivateSubnet
LMISecurityGroupId:
Description: Security group ID for Lambda functions
Value: !Ref LMISecurityGroup
LMIKMSKeyArn:
Description: ARN of the KMS key for Capacity Provider
Value: !GetAtt LMIKMSKey.Arn
Metadata:
SamTransformTest: true