Repository navigation
Expand file tree
/
Copy pathtemplate.yml
More file actions
125 lines (117 loc) · 3.32 KB
/
Copy pathtemplate.yml
File metadata and controls
125 lines (117 loc) · 3.32 KB
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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Cryptocurrency Price Notification System
Globals:
Function:
Runtime: nodejs18.x
Timeout: 30
MemorySize: 256
Environment:
Variables:
SEARCH_HISTORY_TABLE: !Ref SearchHistoryTable
SEARCH_HISTORY_GSI_NAME: "SearchHistoryByTime"
DYNAMODB_TABLE: !Ref SearchHistoryTable
SENDER_EMAIL: !Ref SenderEmail
COINGECKO_API_KEY: !Ref CoinGeckoApiKey
Parameters:
SenderEmail:
Type: String
Description: Verified SES email address for sending notifications
Default: raj.c.khushiram@gmail.com
CoinGeckoApiKey:
Type: String
Description: CoinGecko API key used to query market data
NoEcho: true
SearchHistoryTableName:
Type: String
Description: DynamoDB table name
Default: SearchHistory
Resources:
SearchHistoryTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: SearchHistory
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: searchId
AttributeType: S
- AttributeName: timestamp
AttributeType: N
- AttributeName: entityType
AttributeType: S
KeySchema:
- AttributeName: searchId
KeyType: HASH
- AttributeName: timestamp
KeyType: RANGE
GlobalSecondaryIndexes:
- IndexName: SearchHistoryByTime
KeySchema:
- AttributeName: entityType
KeyType: HASH
- AttributeName: timestamp
KeyType: RANGE
Projection:
ProjectionType: ALL
# API Gateway
CryptoApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
Cors:
AllowMethods: "'GET,POST,OPTIONS'"
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
AllowOrigin: "'*'"
# Microservice 1: Get Crypto Price and Send Email
GetCryptoPriceFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/pricenotification/
Handler: index.handler
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref SearchHistoryTable
- SESCrudPolicy:
IdentityName: !Ref SenderEmail
Events:
GetPrice:
Type: Api
Properties:
RestApiId: !Ref CryptoApi
Path: /crypto/price
Method: POST
Metadata:
BuildMethod: esbuild
BuildProperties:
EntryPoints:
- index.ts
Tsconfig: tsconfig.json
# Microservice 2: Get Search History
GetSearchHistoryFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/searchhistory/
Handler: index.handler
Policies:
- DynamoDBReadPolicy:
TableName: !Ref SearchHistoryTable
Events:
GetHistory:
Type: Api
Properties:
RestApiId: !Ref CryptoApi
Path: /crypto/history
Method: GET
Metadata:
BuildMethod: esbuild
BuildProperties:
EntryPoints:
- index.ts
Tsconfig: tsconfig.json
Outputs:
ApiEndpoint:
Description: API Gateway endpoint URL
Value: !Sub "https://${CryptoApi}.execute-api.${AWS::Region}.amazonaws.com/prod"
SearchHistoryTableName:
Description: DynamoDB table name
Value: !Ref SearchHistoryTable