Skip to content

Instantly share code, notes, and snippets.

@shantanuo
Created October 29, 2020 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shantanuo/29bf5a1466f537a9969668543054825b to your computer and use it in GitHub Desktop.
Save shantanuo/29bf5a1466f537a9969668543054825b to your computer and use it in GitHub Desktop.
A test Lambda function to be integrated into redshift cluster
# https://aws.amazon.com/blogs/big-data/accessing-external-components-using-amazon-redshift-lambda-udfs/
import json
def lambda_handler(event, context):
number = str(event["arguments"][0][0])
import requests
ret = dict()
try:
res = list()
myurl = 'http://some_site.com/InboundDetails.asmx/GetDetails?destination='
page = requests.get(myurl+number[-10:])
res.append((page.content).decode('utf-8'))
print (page.content)
ret['success'] = True
ret['results'] = res
except Exception as e:
ret['success'] = False
ret['error_msg'] = str(e)
return json.dumps(ret)
# Layer: arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-requests:9
@rjvgupta
Copy link

import requests

def lambda_handler(event, context):
res = list()
ret = dict()
myurl = 'http://some_site.com/InboundDetails.asmx/GetDetails?destination='
for argument in event['arguments']:
try:
number = str(arguments[0])
page = requests.get(myurl+number[-10:])
res.append((page.content).decode('utf-8'))
print (page.content)
except Exception as e:
res.append(None)
ret['success'] = True
ret['results'] = res
return json.dumps(ret)

try:
columnValue = argument[2]
response = table.get_item(Key={columnName: columnValue })
res.append(json.dumps(response["Item"]))
except:
res.append(None)

@shantanuo
Copy link
Author

There is a lambda invocation payload response limit of 6 MB. Will I get an error if results array is too large?

@rjvgupta
Copy link

Redshift should ensure batches are small enough to not exceed the limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment