-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-edge-lambda.yaml
176 lines (157 loc) · 4.9 KB
/
api-edge-lambda.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
164
165
166
167
168
169
170
171
172
173
174
175
176
AWSTemplateFormatVersion: '2010-09-09'
Description: Cloudformation stack that create an CloudFrontDistribution with s3
orgin, route53, APIGateway linked with DynamoDBTable through LambdaFunction,
EventBridge, cognito, sqs, sns and stepfunctions.
Parameters:
ACMcertificateArn:
Description: The ACM certificate ARN of the domain, must be in the us-east-1 region.
Type: String
DomainName:
Description: The Domain name
Type: String
EnvironmentName:
Type: String
Resources:
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |
import json
def lambda_handler(event, context):
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
FunctionName: apitest
Handler: index.lambda_handler
Runtime: python3.12
Role: !GetAtt IAMRole.Arn
APIGatewayRestAPI:
Type: AWS::ApiGateway::RestApi
Properties:
Name: RestApi
DependsOn:
- LambdaFunction
APIGatewayResource:
Type: AWS::ApiGateway::Resource
Properties:
RestApiId: !Ref APIGatewayRestAPI
ParentId: !GetAtt APIGatewayRestAPI.RootResourceId
PathPart: '{proxy+}'
DependsOn:
- APIGatewayRestAPI
APIGatewayMethod:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref APIGatewayRestAPI
ResourceId: !Ref APIGatewayResource
HttpMethod: ANY
AuthorizationType: NONE
MethodResponses:
- StatusCode: 200
Integration:
Type: AWS_PROXY
IntegrationResponses:
- StatusCode: 200
IntegrationHttpMethod: POST
Uri: !Sub
- arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations
- LambdaFuncNameArn: !GetAtt LambdaFunction.Arn
APIGatewayDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId: !Ref APIGatewayRestAPI
StageName: !Ref EnvironmentName
DependsOn:
- APIGatewayMethod
APIGatewayPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt LambdaFunction.Arn
Principal: apigateway.amazonaws.com
SourceArn: !Sub
- arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiId}/*/*
- ApiId: !Ref APIGatewayRestAPI
DependsOn:
- APIGatewayDeployment
APIGatewayCustomDomainName:
Type: AWS::ApiGateway::DomainName
Properties:
DomainName: !Sub api.${DomainName}
CertificateArn: !Ref ACMcertificateArn
EndpointConfiguration:
Types:
- EDGE
APIDNS:
Type: AWS::Route53::RecordSetGroup
DependsOn: APIGatewayCustomDomainName
Properties:
HostedZoneName: !Join
- ''
- - !Ref DomainName
- .
RecordSets:
- Name: !Sub api.${DomainName}
Type: A
AliasTarget:
HostedZoneId: !GetAtt APIGatewayCustomDomainName.DistributionHostedZoneId
DNSName: !GetAtt APIGatewayCustomDomainName.DistributionDomainName
APIMapping:
Type: AWS::ApiGateway::BasePathMapping
Properties:
DomainName: !Sub api.${DomainName}
RestApiId: !Ref APIGatewayRestAPI
IAMRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: Policy_api-lambda-db
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:CreateLogGroup
- logs:PutLogEvents
Resource: '*'
## COGNITO#######################################################################################
UserPool:
Type: "AWS::Cognito::UserPool"
Properties:
UserPoolName: "user-pool"
AdminCreateUserConfig:
AllowAdminCreateUserOnly: true
Schema:
- AttributeDataType: String
Name: email
Required: true
- AttributeDataType: String
Name: phone_number
Required: true
Policies:
PasswordPolicy:
MinimumLength: 8
RequireUppercase: true
RequireLowercase: true
RequireNumbers: true
RequireSymbols: true
Outputs:
APIDomainName:
Description: Invoke URL for the custom domain
Value: !Sub https://api.${DomainName}/${EnvironmentName}/${APIGatewayResource}
UserPoolId:
Value: !Ref UserPool