-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
88 lines (84 loc) · 2.83 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A helper for taking snapshot of AWS OpenSearch Service
Parameters:
LambdaVPCId:
Type: String
LambdaVPCSG:
Type: String
Resources:
SnapshotBucket:
Type: AWS::S3::Bucket
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
SnapshotRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: "sts:AssumeRole"
- Effect: Allow
Principal:
Service: es.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/AmazonESFullAccess"
Policies: # 本当は自身のArnをPassRoleするPolicyも必要なのだが自己参照できないので手動で足す
- PolicyName: "AllowTakeElasticSearchSnapshotPolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "s3:ListBucket"
Resource: !GetAtt SnapshotBucket.Arn
- Effect: Allow
Action:
- "s3:GetObject"
- "s3:PutObject"
- "s3:DeleteObject"
Resource: !Sub "${SnapshotBucket.Arn}/*"
- PolicyName: "LambdaWithVPCPolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource: "arn:aws:logs:*:*:*"
- Effect: Allow
Action:
- "ec2:CreateNetworkInterface"
- "ec2:DescribeNetworkInterfaces"
- "ec2:DetachNetworkInterface"
- "ec2:DeleteNetworkInterface"
Resource: "*"
SnapshotHelper:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: snapshot_helper/
Handler: app.lambda_handler
Runtime: python3.9
Timeout: 100
Role: !GetAtt SnapshotRole.Arn
Environment:
Variables:
SNAPSHOT_BUCKET: !Ref SnapshotBucket
VpcConfig:
SecurityGroupIds:
- !Ref LambdaVPCSG
SubnetIds:
- !Ref LambdaVPCId
Outputs:
SnapshotFunctionIamRole:
Description: "Implicit IAM Role created for Lambda function"
Value: !GetAtt SnapshotRole.Arn