-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsamTemplate.yaml
163 lines (153 loc) · 4.54 KB
/
samTemplate.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
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
AWSTemplateFormatVersion: 2010-09-09
Transform: "AWS::Serverless-2016-10-31"
Description: P1
Resources:
photosalbumb2:
Type: AWS::S3::Bucket
Properties:
BucketName: photosalbumb2
photosalbumb1:
Type: AWS::S3::Bucket
Properties:
BucketName: photosalbumb1
LambdaExecutionRoleLF1:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- "sts:AssumeRole"
Description: "The execution role for the lambda LF1."
Path: "/"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
Policies:
- PolicyName: "LambdaLF1Policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource: "arn:aws:s3:::photosalbumb2"
- Effect: Allow
Action:
- rekognition:DetectLabels
Resource: "*"
- Effect: Allow
Action:
- es:ESHttpPut
- es:ESHttpPost
Resource: "*"
RoleName: "LambdaExecutionRoleLF1"
IndexPhotosLF1:
Type: "AWS::Serverless::Function"
Properties:
# DependsOn: LambdaExecutionRoleLF1
FunctionName: IndexPhotosLF1
Handler: lambda_function.lambda_handler
Runtime: python3.6
CodeUri: ./LF1
Description: LF1
MemorySize: 128
Timeout: 30
Role: !GetAtt LambdaExecutionRoleLF1.Arn
Environment:
Variables:
Region: us-east-1
Layers: [arn:aws:lambda:us-east-1:353077126427:layer:Requests:2]
Events:
S3Event:
Type: S3
Properties:
Bucket: !Ref photosalbumb2
Events: s3:ObjectCreated:Put
SearchPhotosLF2:
Type: "AWS::Serverless::Function"
Properties:
# DependsOn: LambdaExecutionRoleLF1
FunctionName: SearchPhotosLF2
Handler: lambda_function.lambda_handler
Runtime: python3.6
CodeUri: ./LF2
Description: LF2
MemorySize: 128
Timeout: 30
Role: !GetAtt LambdaExecutionRoleLF1.Arn
Layers: [arn:aws:lambda:us-east-1:353077126427:layer:Requests:2]
Environment:
Variables:
Region: us-east-1
RestApiPhotoAlbum:
Type: AWS::ApiGateway::RestApi
Properties:
BodyS3Location:
Bucket: b3-photos-album
Key: "ApiPhotoAlbum-dev-swagger.yaml"
Description: "Rest api having search photos and upload photos methods."
Name: RestApiPhotoAlbum
FailOnWarnings: true
EndpointConfiguration:
Types:
- "REGIONAL"
PermissionForAPIToLF2:
Type: "AWS::Lambda::Permission"
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt SearchPhotosLF2.Arn
Principal: apigateway.amazonaws.com
SourceAccount: !Ref "AWS::AccountId"
SourceArn: !Join
- ""
- - "arn:aws:apigateway:us-east-1::/restapis/"
- !Ref RestApiPhotoAlbum
- "/resources/*/methods/GET"
PermissionForS3ToLF1:
Type: "AWS::Lambda::Permission"
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref IndexPhotosLF1
Principal: s3.amazonaws.com
SourceAccount: !Ref "AWS::AccountId"
SourceArn: "arn:aws:s3:::photosalbumb2"
ElasticSearchPhotoAlbum:
Type: AWS::Elasticsearch::Domain
Properties:
DomainName: photo
AccessPolicies:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: "*"
Action: es:*
Resource: "arn:aws:es:us-east-1:353077126427:domain/photo/*"
Condition:
IpAddress:
aws:SourceIp: ["74.72.185.149/24"]
ElasticsearchClusterConfig:
InstanceCount: 1
InstanceType: t3.small.elasticsearch
ElasticsearchVersion: 7.10
DomainEndpointOptions:
EnforceHTTPS: true
EncryptionAtRestOptions:
Enabled: true
NodeToNodeEncryptionOptions:
Enabled: true
EBSOptions:
EBSEnabled: true
VolumeSize: 10
VolumeType: gp2
RestApiPhotoAlbumDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn: [RestApiPhotoAlbum]
Properties:
Description: The v1 deployment of photo album api
RestApiId: !Ref RestApiPhotoAlbum
StageName: v1