Skip to content

Commit

Permalink
refactor: simplify lambda_handler and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
LokoMoloko98 committed Jan 19, 2025
1 parent 63c6c7e commit db79993
Showing 1 changed file with 20 additions and 55 deletions.
75 changes: 20 additions & 55 deletions swift-lift-fare-calculation/swift-lift-fare-calculation.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,25 @@

import json
import boto3
from boto3.dynamodb.conditions import Key

client = boto3.client('dynamodb')
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table('Lokos-Blok-data')
tableName = 'Lokos-Blok-data'
import json
import requests

from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
from botocore.exceptions import ClientError
print("Packages have imported successfully")

def lambda_handler(event, context):
print(event)
body = {}
statusCode = 200
headers = {
"Content-Type": "application/json"
}

lambda_client = boto3.client('lambda')
try:
if event['routeKey'] == "DELETE /blogs/{BlogId}":
table.delete_item(KeyConditionExpression=Key('BlogId').eq(event['pathParameters']['BlogId']))
body = 'Deleted item ' + event['pathParameters']['BlogId']
# elif event['routeKey'] == "GET /blogs/{BlogId}":
# body = table.query(KeyConditionExpression=Key('BlogId').eq(event['pathParameters']['BlogId']))
# body = body["Item"]
# responseBody = [{'BlogId': body['BlogId'], 'BlogTitle': body['BlogTitle'], 'PublishedDate': body['PublishedDate']}]
# body = responseBody
# elif event['routeKey'] == "GET /items":
# body = table.scan()
# body = body["Items"]
# print("ITEMS----")
# print(body)
# responseBody = []
# for items in body:
# responseItems = [
# {'price': float(items['price']), 'BlogId': items['BlogId'], 'name': items['name']}]
# responseBody.append(responseItems)
# body = responseBody
# elif event['routeKey'] == "PUT /items":
# requestJSON = json.loads(event['body'])
# table.put_item(
# Item={
# 'BlogId': requestJSON['BlogId'],
# 'price': Decimal(str(requestJSON['price'])),
# 'name': requestJSON['name']
# })
# body = 'Put item ' + requestJSON['BlogId']
except KeyError:
statusCode = 400
body = 'Unsupported route: ' + event['routeKey']
body = json.dumps(body)
res = {
"statusCode": statusCode,
"headers": {
"Content-Type": "application/json"
},
"body": body
}
return res
print("Processing")

return {
'statusCode': 200,
'body': json.dumps('Process completed successfully')
}

except Exception as e:
print(f"An error occurred: {e}")
return {
'statusCode': 500,
'body': json.dumps('Error occurred during processing')
}

0 comments on commit db79993

Please sign in to comment.