Skip to content

Commit d919208

Browse files
adding utils
1 parent b858d61 commit d919208

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

stac_updater/utils.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import json
2+
3+
4+
def stac_to_sns(stac_item):
5+
"""Convert a STAC item to SNS message (with attributes)"""
6+
7+
try:
8+
collection = stac_item['collection']
9+
except KeyError:
10+
collection = stac_item['properties']['collection']
11+
12+
attributes = {
13+
'bbox.xmin': {
14+
"DataType": "Number",
15+
"StringValue": str(stac_item['bbox'][0])
16+
},
17+
'bbox.ymin': {
18+
"DataType": "Number",
19+
"StringValue": str(stac_item['bbox'][1])
20+
},
21+
'bbox.xmax': {
22+
"DataType": "Number",
23+
"StringValue": str(stac_item['bbox'][2])
24+
},
25+
'bbox.ymax': {
26+
"DataType": "Number",
27+
"StringValue": str(stac_item['bbox'][3])
28+
},
29+
'collection': {
30+
"DataType": "String",
31+
"StringValue": collection
32+
},
33+
}
34+
35+
return {
36+
"Message": json.dumps(stac_item),
37+
"MessageAttributes": attributes
38+
}
39+

0 commit comments

Comments
 (0)