-
Notifications
You must be signed in to change notification settings - Fork 5
/
template.yml
73 lines (70 loc) · 1.82 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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: URL Shortener using API Gateway, DynamoDB and Lambda
Parameters:
LinkTableName:
Type: String
Resources:
Shorten:
Type: AWS::Serverless::Function
Properties:
CodeUri: artifact
Handler: shorten
Runtime: go1.x
Policies: AmazonDynamoDBFullAccess
Timeout: 10
Tracing: Active
Events:
PostEvent:
Type: Api
Properties:
Path: /links
Method: post
Environment:
Variables:
LINK_TABLE: !Ref LinkTableName
ShortenGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${Shorten}
RetentionInDays: 1
Redirect:
Type: AWS::Serverless::Function
Properties:
CodeUri: artifact
Handler: redirect
Runtime: go1.x
Policies: AmazonDynamoDBReadOnlyAccess
Timeout: 10
Tracing: Active
Events:
GetEvent:
Type: Api
Properties:
Path: /links/{shorten_resource}
Method: get
Environment:
Variables:
LINK_TABLE: !Ref LinkTableName
RedirectGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${Redirect}
RetentionInDays: 1
LinkTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Ref LinkTableName
AttributeDefinitions:
- AttributeName: shorten_resource
AttributeType: S
KeySchema:
- AttributeName: shorten_resource
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
Outputs:
ApiUrl:
Description: "API endpoint URL for Prod environment"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/links"