Created
July 13, 2019 00:56
-
-
Save TheSkorm/774e15275487048374f2458760943bb5 to your computer and use it in GitHub Desktop.
hamapi
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 boto3 | |
import json | |
print('Loading function') | |
TABLE="australiancallsigns" | |
db = boto3.client('sdb') | |
def lambda_handler(event, context): | |
'''Demonstrates a simple HTTP endpoint using API Gateway. You have full | |
access to the request and response payload, including headers and | |
status code. | |
To scan a DynamoDB table, make a GET request with the TableName as a | |
query string parameter. To put, update, or delete an item, make a POST, | |
PUT, or DELETE request respectively, passing in the payload to the | |
DynamoDB API as a JSON body. | |
''' | |
print("Received event: " + json.dumps(event, indent=2)) | |
callsign = event["path"].split("/")[1].upper() | |
results = db.get_attributes( | |
DomainName=TABLE, | |
ItemName=callsign, | |
ConsistentRead=True | |
#AttributeNames=["name","suburb","state","type"] | |
) | |
try: | |
print(results) | |
attrs = {v['Name']: v['Value'] for v in results['Attributes']} | |
return { | |
'statusCode': '200', | |
'body': json.dumps(attrs), | |
'headers': { | |
'Content-Type': 'application/json', | |
}, | |
} | |
except KeyError: | |
return { | |
'statusCode': '404', | |
'body': "Not found", | |
'headers': { | |
'Content-Type': 'application/json', | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment