-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.yaml
99 lines (90 loc) · 2.62 KB
/
template.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Election API
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 20
Resources:
MyHttpApi:
Type: AWS::Serverless::HttpApi
Properties:
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: './api.yaml'
MyHttpApiRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service: "apigateway.amazonaws.com"
Action:
- "sts:AssumeRole"
Policies:
- PolicyName: ApiDirectWriteKinesis
PolicyDocument:
Version: '2012-10-17'
Statement:
Action:
- kinesis:PutRecord
Effect: Allow
Resource:
- !GetAtt KinesisStream.Arn
# Define an AWS Kinesis Data Stream
KinesisStream:
Type: "AWS::Kinesis::Stream"
Properties:
ShardCount: 1
# Define and attach a consumer to the Kinesis Data Stream
ApplicationConsumer:
Type: "AWS::Kinesis::StreamConsumer"
Properties:
StreamARN: !GetAtt KinesisStream.Arn
ConsumerName: ApplicationConsumer
ElectionHttpApi:
Type: AWS::Serverless::Function
Properties:
CodeUri: election-api-iwe
Handler: com.aws.handler.VoteHandler::handleRequest
Runtime: java11
MemorySize: 512
Tracing: Active
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref VoteTable
- CloudWatchLambdaInsightsExecutionRolePolicy
Layers:
- !Sub "arn:aws:lambda:${AWS::Region}:580247275435:layer:LambdaInsightsExtension:14"
Environment:
Variables:
TABLE_NAME: !Ref VoteTable
Events:
Stream:
Type: Kinesis
Properties:
Stream: !GetAtt ApplicationConsumer.ConsumerARN
StartingPosition: LATEST
BatchSize: 100
MaximumBatchingWindowInSeconds: 1
ParallelizationFactor: 10
VoteTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Vote
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: "candidate"
AttributeType: S
KeySchema:
- AttributeName: "candidate"
KeyType: HASH
Outputs:
ApiEndpoint:
Description: "Election HTTP API endpoint URL"
Value: !Sub "https://${MyHttpApi}.execute-api.${AWS::Region}.amazonaws.com"