-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
173 lines (161 loc) · 4.99 KB
/
serverless.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
# Service name
service: appsync-eventbridgepipe-subscription-delivery
# Serverless Plugins declaration.
plugins:
- serverless-appsync-plugin
provider:
name: aws
runtime: nodejs18.x
architecture: arm64
region: ${opt:region, "eu-west-1"}
stage: ${opt:stage, "dev"}
stackName: ${self:service}-${self:provider.stage}-stack
timeout: 45
tracing:
lambda: true
custom:
# App Sync declaration.
appSync:
name: appsyncEbPipe
xrayEnabled: true
authentication:
type: API_KEY
apiKeys:
- name: appsyncOrderKey
dataSources: ${file(./dataSources.yml):dataSources}
pipelineFunctions: ${file(./pipelineFunctions.yml):pipelineFunctions}
resolvers: ${file(./resolvers.yml)}
resources:
Resources:
orderTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: orderId
AttributeType: S
KeySchema:
- KeyType: HASH
AttributeName: userId
- KeyType: RANGE
AttributeName: orderId
BillingMode: PAY_PER_REQUEST
TableName: orders
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
TimeToLiveSpecification:
AttributeName: ExpirationTime
Enabled: true
EbPipeServiceRole:
DependsOn:
- orderTable
Type: "AWS::IAM::Role"
Properties:
RoleName: ebPipeRole
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "pipes.amazonaws.com"
Action:
- "sts:AssumeRole"
Policies:
- PolicyName: order-create-appsync-api-policy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "appsync:GraphQL"
- "appsync:GetGraphqlApi"
- "appsync:ListGraphqlApis"
- "appsync:ListApiKeys"
Resource:
- !Join
- ""
- - !Ref GraphQlApi
- "/types/Mutation/fields/createOrder"
- Effect: Allow
Action:
- "dynamodb:DescribeStream"
- "dynamodb:GetRecords"
- "dynamodb:GetShardIterator"
- "dynamodb:ListStreams"
Resource:
- !GetAtt orderTable.Arn
- !GetAtt orderTable.StreamArn
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:CreateLogGroup
- logs:PutLogEvents
Resource: "*"
- Effect: Allow
Action:
- events:InvokeApiDestination
Resource: !GetAtt ApiDestination.Arn
ApiDestination:
Type: AWS::Events::ApiDestination
Properties:
ConnectionArn:
Fn::GetAtt:
- ApiConnection
- Arn
HttpMethod: POST
InvocationEndpoint: !GetAtt GraphQlApi.GraphQLUrl
InvocationRateLimitPerSecond: 300
Name: AppsyncOrderApi
ApiConnection:
Type: AWS::Events::Connection
Properties:
Name: appsync_connection_ebpipe
AuthorizationType: API_KEY
AuthParameters:
ApiKeyAuthParameters:
ApiKeyName: x-api-key
ApiKeyValue: !GetAtt GraphQlApiappsyncOrderKey.ApiKey
PipeCWLogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: 3
LogGroupName: appSyncPipeLogGroup
Pipe:
Type: AWS::Pipes::Pipe
Properties:
RoleArn: !GetAtt EbPipeServiceRole.Arn
Name: appSyncPipe
DesiredState: RUNNING
Source: !GetAtt orderTable.StreamArn
SourceParameters:
DynamoDBStreamParameters:
BatchSize: 1
StartingPosition: LATEST
FilterCriteria:
Filters:
- Pattern: '{"eventName":[{"prefix":"INSERT"}]}'
LogConfiguration:
CloudwatchLogsLogDestination:
LogGroupArn: !GetAtt PipeCWLogGroup.Arn
IncludeExecutionData:
- ALL
Level: TRACE
TargetParameters:
InputTemplate: |-
{
"query": "mutation createOrder($createOrderInput: CreateOrderInput!) { createOrder(createOrderInput: $createOrderInput) { productId } }",
"variables": {
"createOrderInput": {
"userId": <$.dynamodb.Keys.userId.S>,
"orderId": <$.dynamodb.Keys.orderId.S>,
"productId": <$.dynamodb.NewImage.productId.S>
}
}
}
Target:
Fn::GetAtt:
- ApiDestination
- Arn