import requests import json from init import dynamodb_service def get_data_from_dynamodb(item_id): lambda_url = f'https://n0u3bakgmf.execute-api.us-east-1.amazonaws.com/dev/get-item/{item_id}' response = requests.get(lambda_url) if response.status_code == 200: print("Data retrieved from DynamoDB successfully!") return response.json() else: print(f"Error: {response.status_code}, {response.text}") return None def lambda_handler(event, context): try: item_id = event['pathParameters']['id'] response = dynamodb_service.get_item( Key={ 'id': item_id } ) # Eğer item varsa item = response.get('Item', {}) if item: return { 'statusCode': 200, 'body': json.dumps({ 'id': item.get('id'), 'title': item.get('title'), 'keywords': item.get('keywords'), 'createdAt': item.get('createdAt') }) } else: return { 'statusCode': 404, 'body': json.dumps({ 'message': 'Item not found' }) } except Exception as e: return { 'statusCode': 500, 'body': json.dumps({ 'message': 'An error occurred', 'error': str(e) }) }