-
Notifications
You must be signed in to change notification settings - Fork 7
/
template.yml
94 lines (88 loc) · 2.62 KB
/
template.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
Resources:
SQSQueue:
Type: "AWS::SQS::Queue"
Properties:
QueueName: STAGE_NAME-QUEUE_NAME
ProxyApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: STAGE_NAME-QUEUE_NAME-ApiGateway
APIGatewayResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- "ProxyApi"
- "RootResourceId"
PathPart: "API_ENDPOINT"
RestApiId:
Ref: ProxyApi
SQSAPIMethod:
Type: AWS::ApiGateway::Method
DependsOn: SQSQueue
Properties:
RestApiId:
Ref: ProxyApi
ResourceId:
Ref: APIGatewayResource
HttpMethod: "POST"
MethodResponses:
-
StatusCode: "200"
ResponseParameters:
"method.response.header.Access-Control-Allow-Origin": true
AuthorizationType: "NONE"
Integration:
Type: AWS
Credentials: !Sub "${APIGatewaySQSIAM.Arn}"
RequestParameters:
"integration.request.header.Content-Type": "'application/x-www-form-urlencoded'"
IntegrationHttpMethod: POST
RequestTemplates:
"application/json": "Action=SendMessage&MessageBody=$input.body"
PassthroughBehavior: Never
IntegrationResponses:
-
StatusCode: "200"
ResponseParameters:
"method.response.header.Access-Control-Allow-Origin": "'*'"
ResponseTemplates:
"application/json": ""
Uri: !Sub arn:aws:apigateway:us-east-1:sqs:path/${AWS::AccountId}/${SQSQueue.QueueName}
APIGatewayDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn: SQSAPIMethod
Properties:
RestApiId: !Sub "${ProxyApi}"
StageName: STAGE_NAME
APIGatewaySQSIAM:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com
Action: sts:AssumeRole
Policies:
-
PolicyName: STAGE_NAME-QUEUE_NAME-policy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Resource: "*"
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- Effect: Allow
Resource:
- !Sub "${SQSQueue.Arn}"
Action:
- "sqs:SendMessage"
Outputs:
ApiGwUrl:
Value: !Sub "https://${ProxyApi}.execute-api.${AWS::Region}.amazonaws.com/STAGE_NAME/API_ENDPOINT"