Spaces:
Configuration error

File size: 1,601 Bytes
681c53e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
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)
            })
        }