Created
August 14, 2019 06:50
-
-
Save brydavis/11078240cdc231b24c53a00739b70c5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import boto3 | |
from boto3.dynamodb.conditions import Key | |
session = boto3.Session() | |
dynamodb = session.resource('dynamodb', region_name='us-west-2') | |
def lambda_handler(event, context): | |
# { | |
# "product_id": "P000041" | |
# } | |
product_id = json.loads(event["body"])["product_id"] | |
rental = dynamodb.Table("rental").scan( | |
FilterExpression=Key('product_id').eq(product_id) | |
) | |
product = dynamodb.Table("product").get_item( | |
Key={ | |
'product_id': product_id | |
} | |
) | |
customers = [] | |
for user in rental["Items"]: | |
customer = dynamodb.Table("customer").get_item( | |
Key={ | |
"Id": user["user_id"] | |
} | |
) | |
customers.append(customer["Item"]) | |
return { | |
'statusCode': 200, | |
'body': json.dumps({ | |
"rental_info": rental["Items"][0], | |
"product_info": product["Item"], | |
"customer_info": customers, | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment