python-lambda
python-lambda copied to clipboard
aws api invocation failing
hi folks, having one more issue here : when i test the function on the lambda console - it works fine - but when I try to call the API , the following error occurs and the cloudwatch log suggests no parameters were sent.
Traceback (most recent call last):
File "/var/task/service.py", line 11, in handler
"body": e + pi
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
called like so:
curl https://<endpoint>/prod/my_lambda_function --data '{"pi" : 3.14, "e" : 2.718}' -H 'Content-Type: application/json' -v
* Trying 54.192.136.115...
* Connected to l3rj7tq81d.execute-api.us-west-2.amazonaws.com (54.192.136.115) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: //anaconda/ssl/cacert.pem
CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: C=US; ST=Washington; L=Seattle; O=Amazon.com, Inc.; CN=*.execute-api.us-west-2.amazonaws.com
* start date: May 30 00:00:00 2017 GMT
* expire date: Feb 28 23:59:59 2018 GMT
* subjectAltName: host "l3rj7tq81d.execute-api.us-west-2.amazonaws.com" matched cert's "*.execute-api.us-west-2.amazonaws.com"
* issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 Secure Server CA - G4
* SSL certificate verify ok.
> POST /prod/my_lambda_function HTTP/1.1
> Host: l3rj7tq81d.execute-api.us-west-2.amazonaws.com
> User-Agent: curl/7.49.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 26
>
* upload completely sent off: 26 out of 26 bytes
< HTTP/1.1 502 Bad Gateway
< Content-Type: application/json
< Content-Length: 36
< Connection: keep-alive
< Date: Mon, 10 Jul 2017 15:58:50 GMT
< x-amzn-RequestId: aa719f09-6588-11e7-a0b0-657c544d8223
< X-Cache: Error from cloudfront
< Via: 1.1 941cbd1049a1cc3d6d633dce8d55cf36.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: KbnVOMc8Fwkm3cLO_pU2X8R5Sr54XIeUdpq9qtgq77QZF7zww65_zw==
<
* Connection #0 to host l3rj7tq81d.execute-api.us-west-2.amazonaws.com left intact
{"message": "Internal server error"}
I figured out the reason it is failing.
event has no parameters called 'e' or 'pi'. So my guess more changes are needed for invoke to work at parity with the api gateway.
e = float(event['queryStringParameters']['e']) pi = float(event['queryStringParameters']['pi'])
Give example is not working.
This works:
import json
def handler(event, context): # Your code goes here! body = json.loads( event['body'] ) e = body['e'] pi = body['pi'] return { "statusCode": 200, "headers": { "Content-Type": "application/json"}, "body": e + pi }