-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
118 lines (112 loc) · 3.69 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
RivianGearShopScrapper:
Type: AWS::Serverless::Function
Properties:
Handler: main
Runtime: provided.al2
CodeUri: ./scrapper_function.zip
Timeout: 10
Environment:
Variables:
DYNAMODB_TABLE_NAME: !Ref GearShopInventoryTable
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref GearShopInventoryTable
Events:
ScheduledEvent:
Type: ScheduleV2
Properties:
ScheduleExpression: rate(6 hours)
ScheduleExpressionTimezone: UTC
GearShopInventoryStreamNotifier:
Type: AWS::Serverless::Function
Properties:
Handler: main
Runtime: provided.al2
CodeUri: ./notifier_function.zip
Timeout: 30
Events:
DynamoDBStreamEvent:
Type: DynamoDB
Properties:
Stream: !GetAtt GearShopInventoryTable.StreamArn
StartingPosition: LATEST
Environment:
Variables:
SOURCE_ARN: !Sub "arn:aws:ses:${AWS::Region}:${AWS::AccountId}:identity/${CustomDomainEmailIdentity}"
SOURCE_EMAIL: !Ref SourceEmailParameter
REPLY_TO_ADDRESSES: !Ref ReplyToAddressesParameter
BCC_ADDRESSES: !Ref BCCAddressesParameter
REFERRAL_CODE: !Ref RivianReferralCode
Policies:
- AmazonDynamoDBReadOnlyAccess
- SESCrudPolicy:
IdentityName: !Ref SourceEmailParameter
- Version: '2012-10-17'
Statement:
Effect: Allow
Action:
- 'ses:SendEmail'
- 'ses:SendRawEmail'
Resource: "*"
Condition:
StringEquals:
ses:FromAddress: !Ref SourceEmailParameter
GearShopInventoryTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: GearShopInventoryTable
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
AttributeDefinitions:
- AttributeName: Id
AttributeType: S # String type for ProductName
- AttributeName: DateFirstSeen
AttributeType: S # String type for date
KeySchema:
- AttributeName: Id
KeyType: HASH # Partition key
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
GlobalSecondaryIndexes:
- IndexName: DateFirstSeenIndex
KeySchema:
- AttributeName: DateFirstSeen
KeyType: HASH # Partition key for the GSI
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
# SESDomainIdentity:
# Type: AWS::SES::EmailIdentity
# Properties:
# EmailIdentity: !Ref CustomDomainEmailIdentity
# SESSourceEmailIdentity:
# Type: AWS::SES::EmailIdentity
# Properties:
# EmailIdentity: !Ref SourceEmailParameter
Parameters:
CustomDomainEmailIdentity:
Type: String
Description: "The verified custom domain trusted identity to use with SES"
SourceEmailParameter:
Type: String
Description: "The verified email address for sending emails from with SES."
ReplyToAddressesParameter:
Type: String
Description: "Comma-separated list of reply-to addresses to use."
BCCAddressesParameter:
Type: String
Description: "Comma-separated list of BCC email addresses to send new gear notification emails to."
RivianReferralCode:
Type: String
Description: "Rivian owner referral code."
Outputs:
RivianGearShopScrapperArn:
Value: !GetAtt RivianGearShopScrapper.Arn
GearShopInventoryStreamNotifierArn:
Value: !GetAtt GearShopInventoryStreamNotifier.Arn