-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
connector_table_to_function_read.yaml
100 lines (93 loc) · 2.63 KB
/
connector_table_to_function_read.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
Resources:
TriggerFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs18.x
Handler: index.handler
Timeout: 10 # in case eb has delay
InlineCode: |
const AWS = require('aws-sdk');
exports.handler = async (event) => {
console.log(JSON.stringify(event));
const docClient = new AWS.DynamoDB.DocumentClient();
const response = await docClient.put({
TableName: process.env.TABLE_NAME,
Item: {
Id: 'TestInput1234'
}
}).promise();
const data = await new AWS.SQS().receiveMessage({
QueueUrl: process.env.VERIFICATION_QUEUE_URL,
WaitTimeSeconds: 5,
}).promise();
if (data.Messages.length == 0) {
throw 'No messages in the queue!';
}
};
Environment:
Variables:
TABLE_NAME: !Ref Table
VERIFICATION_QUEUE_URL: !Ref VerificationQueue
Policies:
- SQSPollerPolicy:
QueueName: !GetAtt VerificationQueue.QueueName
InvokedFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs18.x
Handler: index.handler
InlineCode: |
const AWS = require('aws-sdk');
exports.handler = async (event) => {
const sqs = new AWS.SQS();
await sqs.sendMessage({
QueueUrl: process.env.VERIFICATION_QUEUE_URL,
MessageBody: "test"
}).promise();
};
Environment:
Variables:
VERIFICATION_QUEUE_URL: !Ref VerificationQueue
Policies:
- SQSSendMessagePolicy:
QueueName: !GetAtt VerificationQueue.QueueName
VerificationQueue:
Type: AWS::SQS::Queue
Table:
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: Id
AttributeType: S
KeySchema:
- AttributeName: Id
KeyType: HASH
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
DynamoDBTableStream:
Type: AWS::Lambda::EventSourceMapping
Properties:
BatchSize: 1
Enabled: true
EventSourceArn: !GetAtt Table.StreamArn
FunctionName: !GetAtt InvokedFunction.Arn
StartingPosition: TRIM_HORIZON
Connector:
Type: AWS::Serverless::Connector
Properties:
Source:
Id: Table
Destination:
Id: InvokedFunction
Permissions:
- Read
ConnectorNotTested:
Type: AWS::Serverless::Connector
Properties:
Source:
Id: TriggerFunction
Destination:
Id: Table
Permissions:
- Write