-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
141 lines (130 loc) · 3.9 KB
/
template.yaml
File metadata and controls
141 lines (130 loc) · 3.9 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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
api-lambda-test
Parameters:
Stage:
Type: String
Default: dev
Globals:
Function:
Timeout: 10
Environment:
Variables:
NODE_OPTIONS: "--enable-source-maps"
STAGE: !Ref Stage
Resources:
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: api-lambda-test-user-pool
CognitoDomainNameResourceServer:
Type: AWS::Cognito::UserPoolResourceServer
Properties:
Identifier: resources
Name: ApiLambdaCognitoUserPoolResourceServer
Scopes:
- ScopeDescription: "Get (scrape)"
ScopeName: get
UserPoolId: !Ref CognitoUserPool
CognitoUserPoolClient:
Type: AWS::Cognito::UserPoolClient
DependsOn: CognitoDomainNameResourceServer
Properties:
UserPoolId: !Ref CognitoUserPool
ClientName: api-lambda-test-user-pool-client
GenerateSecret: true
AllowedOAuthFlowsUserPoolClient: true
AllowedOAuthFlows:
- client_credentials
SupportedIdentityProviders:
- COGNITO
AllowedOAuthScopes:
- resources/get
CognitoDomainName:
Type: AWS::Cognito::UserPoolDomain
Properties:
Domain: api-lambda-test-domain
UserPoolId: !Ref CognitoUserPool
ScraperLambdaRole:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaRole
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonCognitoPowerUser
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: ScraperLambdaS3Policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
- s3:PutLifecycleConfiguration
Resource:
- arn:aws:s3:::lambda-url-to-html-storage
- arn:aws:s3:::lambda-url-to-html-storage/*
SourceBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: lambda-url-to-html-storage
ScraperFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
ImageUri: scraperfunction
Role: !GetAtt ScraperLambdaRole.Arn
Events:
ScraperApiEvent:
Type: Api
Properties:
RestApiId: !Ref ScraperApi
Path: /scrape
Method: get
Metadata:
DockerContext: ./lambda
Dockerfile: Dockerfile
ScraperApi:
Type: AWS::Serverless::Api
DependsOn: CognitoUserPoolClient
Properties:
StageName: !Ref Stage
Auth:
DefaultAuthorizer: ApiCognitoAuthorizer
Authorizers:
ApiCognitoAuthorizer:
UserPoolArn: !GetAtt CognitoUserPool.Arn
AuthorizationScopes:
- resources/get
Outputs:
CognitoDomainName:
Description: "Cognito Domain Name URL"
Value: !Sub "https://${CognitoDomainName}.auth.${AWS::Region}.amazoncognito.com"
ScraperFunction:
Description: "Scraper Lambda Function ARN"
Value: !GetAtt ScraperFunction.Arn
ScraperLambdaIamRole:
Description: "Scraper Lambda IAM Role"
Value: !GetAtt ScraperLambdaRole.Arn
ScraperApiRootResourceId:
Description: "API Gateway Root API Resource ID"
Value: !GetAtt ScraperApi.RootResourceId
ScraperApi:
Description: "API Gateway endpoint URL for Scraper function"
Value: !Sub "https://${ScraperApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}/scrape"
ScraperApiRestApiId:
Description: "API Gateway API ARN"
Value: !Ref ScraperApi
# Export:
# Name: !Sub ${Stage}-ScraperApi-RestApiId