I would like to accomplish the following using Python Lambda function:
- Pull subscription ID from the folder myfiles available within in the S3 bucket
- Query the API in a loop for every subscription ID ( This is the API call: https://faktor.chargify.com/subscriptions/{subscription_id}/components/(component_id)/usages.json)
- Store the result of the API in a new folder in the S3 bucket
So far I was only able to make the following Python code read files from the S3 bucket ( not from the myfiles folder available in the S3 which is requirement 1) , it is also fine if you like to modify the following code as well.
import boto3
def lambda_handler(event, context):
s3 = boto3.client("s3")
if event: print("Event : ", event)
file_obj = event["Records"][0]
filename = str(file_obj['s3']['object']['key'])
print("Filename: " , filename)
fileObj = s3.get_object(Bucket = "chargifytesting" , Key=filename)
file_content = fileObj["Body"].read().decode('utf-8')
print(file_content)
Could you please help me with this on urgent basis?
Regards,
Priya
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
23 | 24 | 25 | 26 | 27 | 28 | 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 | 1 | 2 | 3 | 4 | 5 |
Get Free Quote!
360 Experts Online