Giter Site home page Giter Site logo

Comments (5)

jorgebastida avatar jorgebastida commented on June 22, 2024

Have you check in the "Request Paths" section? That {name} is not a Query string but a request path.

This is how the dashboard looks like for the apigateway example (https://github.com/jorgebastida/gordon/tree/master/examples/apigateway)

captura de pantalla 2016-06-02 16 47 58

from gordon.

pmontrasio avatar pmontrasio commented on June 22, 2024

You're right (obviously), the name parameter is in the Request Paths.

I read http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-lambda.html and realized that I was missing the configuration for the Integration Request.

I added this manually:

picture_2016-06-03_16 32 08 png

The test in the API Gateway page passed. I deployed the API and it works with curl as well.

I have to figure out with piece of configuration I'm missing in gordon. I expected I had nothing to do and that declaring the parameter would setup the Integration Request too.

from gordon.

pmontrasio avatar pmontrasio commented on June 22, 2024

I made further investigations.

I cloned the gordon repository, moved to the examples/apigateway folder, changed the name of the bucket and deployed the example.

That also doesn't configure the Integration Request.

You can try curl https://dpyif1qb1g.execute-api.eu-west-1.amazonaws.com/dev/shop/x which is defined as /shop/{item} in settings.yml

I modified the example to print out the events object, which is empty.
Which is the way to access the value of item? In my previous comment I show how to do it using Integration Request.

I added an explicit parameters definition:

/shop/{item}:
  methods: GET
  integration:
    lambda: helloworld.hellojs
    parameters:
      integration.request.querystring.item: method.request.path.item

(I switched to helloworld.hellojs because I'm more familiar with JS).

The AWS documentation hints that the item from the URL path should go to the right and the destination should go to the left. I'm not sure that querystring is the way to tell AWS to put that item into the events object.

With those lines gordon apply fails:

Applying project...
  0001_p.json (cloudformation)
    ✓ No updates are to be performed.
  0002_pr_r.json (custom)
    ✓ code/contrib_lambdas_version.zip (dcfc39a5)
    ✓ code/helloworld_hellojs.zip (25db66b4)
    ✓ code/helloworld_hellopy.zip (5cecbbbc)
  0003_r.json (cloudformation)
    UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS waiting... |                       

Unfortunately there is no detailed error message.

All the examples that define parameters for the API Gateway don't use those parameters in the lambda functions. Could you give a working example of a lambda function that uses those parameters? Thanks.

A final remark: in the spirit of convention over configuration (I remember your comment on HN) I think that we shouldn't even declare how to map parameters to events. gordon should automatically configure the API Gateway to pass any parameter to lambda. Path and querystring parameters should be the same. Parameters from the headers could get some special name, such has HEADER_parameter.

The last two lines here shouldn't be needed:

/parameters:
  # http://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html
  methods: GET
  parameters:
    method.request.header.color: True
  integration:
    lambda: helloworld.hellopy
    responses:
    - pattern: ""
      code: "200"
    parameters:
      integration.request.querystring.color: method.request.header.color

from gordon.

pmontrasio avatar pmontrasio commented on June 22, 2024

I eventually realized that if I POST a JSON to an API Gateway URL it gets forwarded to the events object in Lambda. This is from https://github.com/jorgebastida/gordon/tree/master/examples/apigateway

$ curl -X POST -H "Content-Type: application/json" -d '{"this":"is","json":"data"}' \
https://your-api-gw-url.amazonaws.com/dev/complex/implementation

"Hello from js!\nEvent\n{\n  \"this\": \"is\",\n  \"json\": \"data\"\n}\n"

That is totally OK for sending data.

from gordon.

azizmb avatar azizmb commented on June 22, 2024

Just found this. @pmontrasio wondering if #117 is related to this?

from gordon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.