-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudformation.yml
174 lines (151 loc) · 4.33 KB
/
cloudformation.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
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
AWSTemplateFormatVersion: 2010-09-09
Parameters:
LogBucket:
Type: String
LogPrefix:
Type: String
Default: s3-access/
StorageExpirationInDays:
Type: Number
MinValue: 1
Default: 1
ProductPath:
Type: String
Default: https://grfn.asf.alaska.edu/door/download/
UrsHostname:
Type: String
Default: urs.earthdata.nasa.gov
AllowedValues:
- urs.earthdata.nasa.gov
- uat.urs.earthdata.nasa.gov
UrsUsername:
Type: String
UrsPassword:
Type: String
NoEcho: true
DomainName:
Type: String
CertificateArn:
Type: String
Outputs:
ApiEndpoint:
Value: !Sub "https://${RestApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}/"
Resources:
Secret:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Ref AWS::StackName
SecretString: !Sub |-
{
"netrc_content": "machine ${UrsHostname} login ${UrsUsername} password ${UrsPassword}"
}
Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref AWS::StackName
LifecycleConfiguration:
Rules:
- Status: Enabled
AbortIncompleteMultipartUpload:
DaysAfterInitiation: 1
- Status: Enabled
ExpirationInDays: !Ref StorageExpirationInDays
LoggingConfiguration:
DestinationBucketName: !Ref LogBucket
LogFilePrefix: !Sub "${LogPrefix}${AWS::StackName}/"
PublicAccessBlockConfiguration:
BlockPublicAcls: true
IgnorePublicAcls: true
CorsConfiguration:
CorsRules:
- AllowedMethods:
- GET
- HEAD
AllowedOrigins:
- "*.asf.alaska.edu"
- "null"
BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref Bucket
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: "*"
Action: s3:GetObject
Resource: !Sub "${Bucket.Arn}/*"
ReformatStack:
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
Name: !Sub "${AWS::StackName}-reformat"
Bucket: !Ref Bucket
ProductPath: !Ref ProductPath
SecretArn: !Ref Secret
TemplateURL: reformat/cloudformation.yml
CustomDomainName:
Type: AWS::ApiGateway::DomainName
Properties:
DomainName: !Ref DomainName
CertificateArn: !Ref CertificateArn
BasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
Properties:
DomainName: !Ref CustomDomainName
RestApiId: !Ref RestApi
RestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: !Ref AWS::StackName
Body:
openapi: 3.0.1
info:
title: geospatial-services
version: 0.0.1
paths:
/reformat:
get:
parameters:
- name: product
in: query
required: true
- name: layer
in: query
required: true
responses:
'307':
description: success
default:
description: error
x-amazon-apigateway-request-validator: parameters-only
x-amazon-apigateway-integration:
type: aws_proxy
uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ReformatStack.Outputs.LambdaArn}/invocations"
contentHandling: CONVERT_TO_TEXT
httpMethod: POST
passthroughBehvaior: when_no_match
responses:
default:
statusCode: 200
x-amazon-apigateway-request-validators:
parameters-only:
validateRequestParameters: true
validateRequestBody: false
DeploymentREPLACEME:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId: !Ref RestApi
Stage:
Type: AWS::ApiGateway::Stage
Properties:
StageName: geospatial
RestApiId: !Ref RestApi
DeploymentId: !Ref DeploymentREPLACEME
LambdaPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt ReformatStack.Outputs.LambdaArn
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*"