Guest User

Untitled

a guest
Jan 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import json
  2.  
  3. def lambda_handler(event, context):
  4. # TODO implement
  5. now = datetime.datetime.now()
  6. cur_day = "{}{}{}".format(now.strftime('%d'),now.strftime('%m'),now.year)
  7. print(cur_day)
  8. my_contents = get_data_from_s3_file('myBucket', 'myFile')
  9. return {
  10. 'statusCode': 200,
  11. 'body': json.dumps('Hello from Lambda!')
  12. }
  13.  
  14. def get_data_from_s3_file(bucket, my_file):
  15. """Read the contents of the file as a string and split by lines"""
  16. my_data = s3.get_object(Bucket=bucket, Key=my_file)
  17. my_text = my_data['Body'].read().decode('utf-8').split('n')
  18.  
  19. return my_text
  20.  
  21. pip install python-lambda-local
  22. python-lambda-local -l lib/ -f lambda_handler -t 5 pythonLambdaLocalTest.py event.json
  23.  
  24. raise EndpointConnectionError(endpoint_url=request.url, error=e)
  25. botocore.exceptions.EndpointConnectionError: Could not connect to the
  26. endpoint URL: "https://myBucket/myfile"
  27.  
  28. sam local start-api -t pythonLambdaLocalTest.yaml
  29.  
  30. 2019-01-21 16:56:30 Found credentials in shared credentials file: ~/.aws/credentials
  31. Error: Template does not have any APIs connected to Lambda functions
Add Comment
Please, Sign In to add comment