import json
import boto3
def lambda_handler(event, context):
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table('User')
/*
api gateway 쓸 때 pathParameters 해줘야 하고
처음에 testcase에 'name' : "/jungyr24" 이렇게 슬래시까지 포함돼있어서 오류 났다 슬래시빼고 해결
*/
resp = table.get_item(Key={"Name": event['pathParameters']['name']})
print("item type", type(resp['Item']))
return {
"statusCode":200,
# "headers": {
# "Content-Type":"application/json",
# "Access-Control-Allow-Headers" : "Content-Type",
# "Access-Control-Allow-Origin": "*",
# "Access-Control-Allow-Methods": "OPTIONS,POST,GET",
# "Access-Control-Allow-Credentials": "true"
# },
/*
응답 형식이 자꾸 잘못 됐다고 해서 json형식으로 바꿔주니까 해결됨 . dict -> json타입으로 바꿔줘야된다
*/
"body": json.dumps(resp['Item'])
}
잘 되는 모습.