New AWS Lambda + Apigee Sample code

5 8 2,511

Hi Team,

@Nigel posted demo code showing Apigee proxy AWS Lambda calls. Thank you to Laurence from enkidootech.com to confirm that it works.

https://github.com/apigee/a127-lambda-petstore-sample

Comments
alan_williams
New Member

Thanks for sharing this. I took that sample and tweaked it sightly for my use case, deployed it to Edge Cloud and when I make a call to the API (curl -i) for some reason the output is the full swagger doc. Any idea why that's happening?

alan
New Member

Can you post the full curl command ?

alan_williams
New Member

curl -i https://.apigee.net/v1/<proxy-name>;

and the output is the full swagger doc in json format.

Not applicable

Hi Alan,

To access the petstore functionality you need to add the resource paths to your url string:

e.g. GET https://apigee.net/v1/<proxy-name>/pets - will return the full list of pets

GET https://apigee.net/v1/<proxy-name>/pets/{petid} will return a single pet

If you load the swagger doc into apistudio.io you can easily see all of the available operations.

alan_williams
New Member

@Nigel Walters have you gotten this to work without API Gateway in the path? I.e. Apigee -> Lambda?

Not applicable

Hi Alan, yes, we have that working. Within the a127 lambda petstore sample github project you can find an example of Apigee calling AWS Lambda directly here: https://github.com/apigee/a127-lambda-petstore-sample/tree/master/a127_proxy_to_lambda

Please let me know if you have any queries around it.

alan_williams
New Member

Thanks @Nigel Walters that's been helpful. Do you know of a way to manage custom http status codes from Lambda within Swagger? As you know Lambda always returns a status 200 but the functionality of the function may need to return a message indicative of status that's not "OK" so is there a way to do this with just Swagger + Lambda? I know API Gateway can do it, but if possible I'd like to eliminate the extra middle man.

alan
New Member

If you look at line 79, I think that answers your question.

https://github.com/apigee/a127-lambda-petstore-sample/blob/master/a127_proxy_to_lambda/api/controlle...

     if (/.*BAD_REQ.*/.test( JSON.stringify(data) ) ){
       console.log("BAD REQUEST");
       res.status(400)
     } else if (/.*INT_ERROR.*/.test( JSON.stringify(data) ) ) {
       console.log("INTERNAL ERROR");
       res.status(500)
     }

Basically, you can inspect the payload coming from AWS Lambda, then write some logic to return the correct HTTP response code. Its a bit of a pain in the ass because you need to account for both application level errors from Lambda, and potential system errors from Lambda too. (Link to all system level errors from Lambda)

Version history
Last update:
‎03-15-2016 03:00 PM
Updated by: