-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython.py
59 lines (47 loc) · 1.29 KB
/
python.py
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
import urllib3
import boto3
import json
import urllib.parse
import os
import uuid
client = boto3.client('stepfunctions')
def run_ecs_task():
# INPUT -> { (unique)"TransactionID": "foo", "Type":"PURCHASE"}
try:
response = client.start_execution(
stateMachineArn=os.environ['step'],
name=str(uuid.uuid1()),
input='{\"Comment\" : \"insert your json here\"}',
)
except Exception as e:
print(e)
def fetch_transaction_id():
try:
http = urllib3.PoolManager()
uri = os.environ['uri']
json_data = http.request('GET', uri).data
print(json_data)
result = json.loads(json_data)
res = result['Transaction_ID']
return res
except Exception as e:
print(e)
def upload_dynamodb(res):
try:
Transaction_ID = res
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Transaction_Table')
table.put_item(
Item={
'Transaction_ID': Transaction_ID,
}
)
except Exception as e:
print(e)
def lambda_handler(event, context):
try:
run_ecs_task()
res = fetch_transaction_id()
upload_dynamodb(res)
except Exception as e:
print(e)