Skip to content

Commit 73c86a8

Browse files
committed
Many Notes
1 parent 295a457 commit 73c86a8

File tree

1 file changed

+358
-0
lines changed

1 file changed

+358
-0
lines changed

unicorn_contracts/Notes.md

Lines changed: 358 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,358 @@
1+
## EventBridge
2+
3+
arn:aws:events:ap-southeast-1:976509018599:event-bus/UnicornPropertiesEventBus-Local
4+
arn:aws:events:ap-southeast-1:976509018599:rule/UnicornPropertiesEventBus-Local/properties.catchall
5+
6+
7+
8+
## Pipes Source and Detail
9+
10+
Pipes arn: arn:aws:pipes:ap-southeast-1:976509018599:pipe/Contracts
11+
12+
Event from Lambda:
13+
14+
{
15+
"Time": "08/02/2023 16: 06: 56",
16+
"Source": "unicorn.contracts",
17+
"DetailType": "ContractStatusChanged",
18+
"Detail": {
19+
"contract_last_modified_on": "08/02/2023 16:06:56",
20+
"property_id": "usa/anytown/main-street/153",
21+
"contract_id": "25a238b6-3143-41e2-a7b9-d2b66be4bb03",
22+
"contract_status": "DRAFT"
23+
},
24+
"EventBusName": "UnicornPropertiesEventBus-Local"
25+
}
26+
27+
Event from Pipes
28+
{
29+
"version": "0",
30+
"id": "49ea11e1-41ee-fd51-545a-d2ae6f203195",
31+
"detail-type": "Event from null",
32+
"source": "Pipe Contracts",
33+
"account": "976509018599",
34+
"time": "2023-02-06T09:06:32Z",
35+
"region": "ap-southeast-1",
36+
"resources": [],
37+
"detail": {
38+
"contract_last_modified_on": "06/02/2023 09:06:31",
39+
"property_id": "usa/anytown/main-street/150",
40+
"contract_id": "c66d4ffc-27e6-42d2-b635-121eee31cda3",
41+
"contract_status": "DRAFT"
42+
}
43+
}
44+
45+
{
46+
"version": "0",
47+
"id": "89961743-7396-b27b-4874-50949f07c9bb",
48+
"detail-type": "Event from null",
49+
"source": "Pipe Contracts",
50+
"account": "976509018599",
51+
"time": "2023-02-08T15:41:01Z",
52+
"region": "ap-southeast-1",
53+
"resources": [],
54+
"detail": {
55+
"eventID": "faae270c2d33f1556745b22178c47f4a",
56+
"eventName": "INSERT",
57+
"eventVersion": "1.1",
58+
"eventSource": "aws:dynamodb",
59+
"awsRegion": "ap-southeast-1",
60+
"dynamodb": {
61+
"ApproximateCreationDateTime": 1675870861,
62+
"Keys": {
63+
"property_id": {
64+
"S": "usa/anytown/main-street/152"
65+
}
66+
},
67+
"NewImage": {
68+
"contract_last_modified_on": {
69+
"S": "08/02/2023 15:41:00"
70+
},
71+
"address": {
72+
"M": {
73+
"country": {
74+
"S": "USA"
75+
},
76+
"number": {
77+
"N": "152"
78+
},
79+
"city": {
80+
"S": "Anytown"
81+
},
82+
"street": {
83+
"S": "Main Street"
84+
}
85+
}
86+
},
87+
"seller_name": {
88+
"S": "John Smith"
89+
},
90+
"contact_created": {
91+
"S": "08/02/2023 15:41:00"
92+
},
93+
"contract_id": {
94+
"S": "d4745ecb-ac96-4764-ba88-6d2761e96e88"
95+
},
96+
"contract_status": {
97+
"S": "DRAFT"
98+
},
99+
"property_id": {
100+
"S": "usa/anytown/main-street/152"
101+
}
102+
},
103+
"SequenceNumber": "46534700000000000643392612",
104+
"SizeBytes": 303,
105+
"StreamViewType": "NEW_IMAGE"
106+
},
107+
"eventSourceARN": "arn:aws:dynamodb:ap-southeast-1:976509018599:table/uni-prop-local-contract-ContractsTable-10X09BGH3CXR2/stream/2023-02-01T15:09:35.555"
108+
}
109+
}
110+
111+
PipeTargetEventBridgeEventBusParameters
112+
https://docs.aws.amazon.com/eventbridge/latest/pipes-reference/API_PipeTargetEventBridgeEventBusParameters.html
113+
114+
## Pipes Transform
115+
116+
```
117+
{
118+
"contract_last_modified_on": <$.dynamodb.NewImage.contract_last_modified_on.S>,
119+
"property_id": <$.dynamodb.NewImage.property_id.S>,
120+
"contract_id": <$.dynamodb.NewImage.contract_id.S>,
121+
"contract_status": <$.dynamodb.NewImage.contract_status.S>
122+
}
123+
```
124+
125+
{
126+
"version": "0",
127+
"id": "7ba242f7-5a2c-81d3-7e08-2837996cb2d3",
128+
"detail-type": "Event from null",
129+
"source": "Pipe Contracts",
130+
"account": "976509018599",
131+
"time": "2023-02-08T16:06:56Z",
132+
"region": "ap-southeast-1",
133+
"resources": [],
134+
"detail": {
135+
"contract_last_modified_on": "08/02/2023 16:06:56",
136+
"property_id": "usa/anytown/main-street/153",
137+
"contract_id": "25a238b6-3143-41e2-a7b9-d2b66be4bb03",
138+
"contract_status": "DRAFT"
139+
}
140+
}
141+
142+
## Pipes Describe
143+
144+
aws pipes describe-pipe --name=Contracts
145+
{
146+
"Arn": "arn:aws:pipes:ap-southeast-1:976509018599:pipe/Contracts",
147+
"CreationTime": "2023-02-01T15:11:37+00:00",
148+
"CurrentState": "RUNNING",
149+
"Description": "Send contract updates from DDB to EB",
150+
"DesiredState": "RUNNING",
151+
"EnrichmentParameters": {},
152+
"LastModifiedTime": "2023-02-08T16:06:53+00:00",
153+
"Name": "Contracts",
154+
"RoleArn": "arn:aws:iam::976509018599:role/service-role/Amazon_EventBridge_Pipe_Contracts_9f0bbeeb",
155+
"Source": "arn:aws:dynamodb:ap-southeast-1:976509018599:table/uni-prop-local-contract-ContractsTable-10X09BGH3CXR2/stream/2023-02-01T15:09:35.555",
156+
"SourceParameters": {
157+
"DynamoDBStreamParameters": {
158+
"BatchSize": 1,
159+
"StartingPosition": "LATEST"
160+
}
161+
},
162+
"StateReason": "No records processed",
163+
"Tags": {},
164+
"Target": "arn:aws:events:ap-southeast-1:976509018599:event-bus/UnicornPropertiesEventBus-Local",
165+
"TargetParameters": {
166+
"InputTemplate": "{\n \"contract_last_modified_on\": <$.dynamodb.NewImage.contract_last_modified_on.S>,\n \"property_id\": <$.dynamodb.NewImage.property_id.S>,\n \"contract_id\": <$.dynamodb.NewImage.contract_id.S>,\n \"contract_status\": <$.dynamodb.NewImage.contract_status.S>\n}"
167+
}
168+
}
169+
170+
aws pipes update-pipe --name="Contracts" --role-arn=arn:aws:iam::976509018599:role/service-role/Amazon_EventBridge_Pipe_Contracts_9f0bbeeb --target-parameters EventBridgeEventBusParameters="{DetailType=ContractStatusChanged,Source=unicorn.contracts}"
171+
172+
aws pipes describe-pipe --name=Contracts {
173+
"Arn": "arn:aws:pipes:ap-southeast-1:976509018599:pipe/Contracts",
174+
"CreationTime": "2023-02-01T15:11:37+00:00",
175+
"CurrentState": "RUNNING",
176+
"Description": "Send contract updates from DDB to EB",
177+
"DesiredState": "RUNNING",
178+
"EnrichmentParameters": {},
179+
"LastModifiedTime": "2023-02-08T16:39:59+00:00",
180+
"Name": "Contracts",
181+
"RoleArn": "arn:aws:iam::976509018599:role/service-role/Amazon_EventBridge_Pipe_Contracts_9f0bbeeb",
182+
"Source": "arn:aws:dynamodb:ap-southeast-1:976509018599:table/uni-prop-local-contract-ContractsTable-10X09BGH3CXR2/stream/2023-02-01T15:09:35.555",
183+
"SourceParameters": {
184+
"DynamoDBStreamParameters": {
185+
"BatchSize": 1,
186+
"StartingPosition": "LATEST"
187+
}
188+
},
189+
"StateReason": "No records processed",
190+
"Tags": {},
191+
"Target": "arn:aws:events:ap-southeast-1:976509018599:event-bus/UnicornPropertiesEventBus-Local",
192+
"TargetParameters": {
193+
"EventBridgeEventBusParameters": {
194+
"DetailType": "ContractStatusChanged",
195+
"Source": "unicorn.contracts"
196+
},
197+
"InputTemplate": "{\n \"contract_last_modified_on\": <$.dynamodb.NewImage.contract_last_modified_on.S>,\n \"property_id\": <$.dynamodb.NewImage.property_id.S>,\n \"contract_id\": <$.dynamodb.NewImage.contract_id.S>,\n \"contract_status\": <$.dynamodb.NewImage.contract_status.S>\n}"
198+
}
199+
}
200+
201+
## Lambda Log
202+
203+
[{'Time': '09/02/2023 03:12:51', 'Source': 'unicorn.contracts', 'DetailType': 'ContractStatusChanged', 'Detail': '{"contract_last_modified_on": "09/02/2023 03:12:51", "property_id": "usa/anytown/main-street/174", "contract_id": "fb759ce7-aad7-47bd-afa8-60241f0f790a", "contract_status": "DRAFT"}', 'EventBusName': 'UnicornPropertiesEventBus-Local'}]
204+
205+
{'FailedEntryCount': 0, 'Entries': [{'EventId': '8291a24b-872b-fc1f-3c82-66b67ba36f81'}], 'ResponseMetadata': {'RequestId': '0a6799ab-265e-45cc-8919-3d723261a699', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '0a6799ab-265e-45cc-8919-3d723261a699', 'content-type': 'application/x-amz-json-1.1', 'content-length': '85', 'date': 'Thu, 09 Feb 2023 03:12:51 GMT'}, 'RetryAttempts': 0}}
206+
207+
## Permissions Issues
208+
aws events put-permission --event-bus-name=UnicornPropertiesEventBus-Local --principal=976509018599 --action=events:PutEvents --statement-id=PutForAll
209+
210+
aws logs put-resource-policy --policy-name AllowLogEvent --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Sid": "EventBridgeToCloudWatchLogs", "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] }, "Action": "logs:PutLogEvents", "Resource": "arn:aws:logs:*:976509018599:log-group:*" } ] }'
211+
212+
aws logs put-resource-policy --policy-name AllowLogEvent --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Sid": "EventBridgeToCloudWatchLogs", "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com","delivery.logs.amazonaws.com" ] }, "Action": ["logs:PutLogEvents", "logs:CreateLogStream"], "Resource": "arn:aws:logs:*:976509018599:log-group:*:*" } ] }'
213+
214+
aws events describe-event-bus --name=UnicornPropertiesEventBus-Local --output=json --query=Policy
215+
216+
```
217+
{
218+
"Statement": [
219+
{
220+
"Action": [
221+
"logs:CreateLogStream",
222+
"logs:PutLogEvents"
223+
],
224+
"Effect": "Allow",
225+
"Principal": {
226+
"Service": [
227+
"events.amazonaws.com",
228+
"delivery.logs.amazonaws.com"
229+
]
230+
},
231+
"Resource": "arn:aws:logs:ap-southeast1::log-group:/aws/events/*:*",
232+
"Sid": "TrustEventsToStoreLogEvent"
233+
}
234+
],
235+
"Version": "2012-10-17"
236+
}
237+
238+
[
239+
{
240+
"Sid": "ContactsPublishEventsPolicy-Local",
241+
"Effect": "Allow",
242+
"Principal": {
243+
"AWS": "arn:aws:iam::976509018599:root"
244+
},
245+
"Action": "events:PutEvents",
246+
"Resource": "arn:aws:events:ap-southeast-1:976509018599:event-bus/UnicornPropertiesEventBus-Local"
247+
},
248+
{
249+
"Sid": "PutForAll",
250+
"Effect": "Allow",
251+
"Principal": {
252+
"AWS": "arn:aws:iam::976509018599:root"
253+
},
254+
"Action": "events:PutEvents",
255+
"Resource": "arn:aws:events:ap-southeast-1:976509018599:event-bus/UnicornPropertiesEventBus-Local"
256+
},
257+
{
258+
"Sid": "CreateRulePolicy-Local",
259+
"Effect": "Allow",
260+
"Principal": {
261+
"AWS": "arn:aws:iam::976509018599:root"
262+
},
263+
"Action": [
264+
"events:PutRule",
265+
"events:DeleteRule",
266+
"events:DescribeRule",
267+
"events:DisableRule",
268+
"events:EnableRule",
269+
"events:PutTargets",
270+
"events:RemoveTargets"
271+
],
272+
"Resource": "arn:aws:events:ap-southeast-1:976509018599:rule/UnicornPropertiesEventBus-Local/*",
273+
"Condition": {
274+
"StringEquals": {
275+
"events:source": [
276+
"unicorn.contracts",
277+
"unicorn.properties"
278+
]
279+
},
280+
"Null": {
281+
"events:source": "false"
282+
},
283+
"StringEqualsIfExists": {
284+
"events:creatorAccount": "${aws:PrincipalAccount}"
285+
}
286+
}
287+
}
288+
]
289+
```
290+
291+
292+
```
293+
{
294+
"Version": "2012-10-17",
295+
"Statement": [
296+
{
297+
"Sid": "ContactsPublishEventsPolicy-Local",
298+
"Effect": "Allow",
299+
"Principal": {
300+
"AWS": "arn:aws:iam::976509018599:root"
301+
},
302+
"Action": "events:PutEvents",
303+
"Resource": "arn:aws:events:ap-southeast-1:976509018599:event-bus/UnicornPropertiesEventBus-Local"
304+
},
305+
{
306+
"Sid": "PutForAll",
307+
"Effect": "Allow",
308+
"Principal": {
309+
"AWS": "arn:aws:iam::976509018599:root"
310+
},
311+
"Action": "events:PutEvents",
312+
"Resource": "arn:aws:events:ap-southeast-1:976509018599:event-bus/UnicornPropertiesEventBus-Local"
313+
},
314+
{
315+
"Sid": "CreateRulePolicy-Local",
316+
"Effect": "Allow",
317+
"Principal": {
318+
"AWS": "arn:aws:iam::976509018599:root"
319+
},
320+
"Action": [
321+
"events:PutRule",
322+
"events:DeleteRule",
323+
"events:DescribeRule",
324+
"events:DisableRule",
325+
"events:EnableRule",
326+
"events:PutTargets",
327+
"events:RemoveTargets"
328+
],
329+
"Resource": "arn:aws:events:ap-southeast-1:976509018599:rule/UnicornPropertiesEventBus-Local/*",
330+
"Condition": {
331+
"StringEquals": {
332+
"events:source": [
333+
"unicorn.contracts",
334+
"unicorn.properties"
335+
]
336+
},
337+
"Null": {
338+
"events:source": "false"
339+
},
340+
"StringEqualsIfExists": {
341+
"events:creatorAccount": "${aws:PrincipalAccount}"
342+
}
343+
}
344+
}
345+
]
346+
}
347+
```
348+
349+
Lambda Role:
350+
{
351+
"Statement": [
352+
{
353+
"Action": "events:PutEvents",
354+
"Resource": "arn:aws:events:ap-southeast-1:976509018599:event-bus/UnicornPropertiesEventBus-Local",
355+
"Effect": "Allow"
356+
}
357+
]
358+
}

0 commit comments

Comments
 (0)