Coder Social home page Coder Social logo

Comments (8)

kkesley avatar kkesley commented on June 3, 2024

it turns out it's because I did not use lambda proxy integration. My bad.

from aws-lambda-go.

m1ch3lp3r3z avatar m1ch3lp3r3z commented on June 3, 2024

Hi @kkesley I'm having the same issue after enabling lambda integration in my serverless.yml, because I need it for custom status codes (302). Could you please describe little more how you solved the problem?. Thank you!

from aws-lambda-go.

kkesley avatar kkesley commented on June 3, 2024

Hi @m1ch3lp3r3z TBH I made a mistake by not providing any details to my issue and I forgot about the issue I was having. Can you provide an example for your serverless.yml detail? I might still remember when I see your configuration.

from aws-lambda-go.

m1ch3lp3r3z avatar m1ch3lp3r3z commented on June 3, 2024

Hi @kkesley, thank you for your quick reply. I'm trying to implement a lambda function that will receive data from a contact us form (application/x-www-form-urlencoded) and will return a 302 status code and Location header. My handler definition in serverless.yml looks like:

functions:
  contactUs:
    handler: go/bin/handlers/contact_us
    warmup:
      enabled: false
    events:
      - http:
          path: ${self:custom.apiVersion}/contact-us
          method: post
          cors: false
          integration: lambda
          response:
            statusCodes: 
              302:
                pattern: '' # Default response method
                headers:
                  Content-Type: "'text/html'"
                  Location: integration.response.header.location

Since I added the lambda integration I'm getting this error from the API Gateway:

{"errorMessage":"json: cannot unmarshal object into Go struct field APIGatewayProxyRequest.body of type string","errorType":"UnmarshalTypeError"}

The request is not even reaching my function so I'm guessing API Gateway is trying to parse the input as a JSON, but I fail to see where to change that.

Thank you!

from aws-lambda-go.

kkesley avatar kkesley commented on June 3, 2024

@m1ch3lp3r3z for me, I'm not using integration: lambda and just send the response in the code.

return events.APIGatewayProxyResponse{
		Body:            "some string",
		IsBase64Encoded: false,
		Headers: map[string]string{
			"Content-Type":                "text/plain",
			"Access-Control-Allow-Origin": "*",
		},
		StatusCode: 302,
	}, nil

from aws-lambda-go.

m1ch3lp3r3z avatar m1ch3lp3r3z commented on June 3, 2024

@kkesley I actually started there, as soon as I set the StatusCode: 302 in my returned Response object I get "message": "Missing Authentication Token" (403). I think API Gateway by default only allows success or error status codes (out of the lambda fn). Wondering if you don't have any other configuration related to the status code 302 in your serverless.yml

from aws-lambda-go.

kkesley avatar kkesley commented on June 3, 2024

@m1ch3lp3r3z Hmm... I didn't set the response field in the serverless.yml. Is it only happening for 302 status code or can you test another one? e.g. 202 or 400?

from aws-lambda-go.

m1ch3lp3r3z avatar m1ch3lp3r3z commented on June 3, 2024

Wow... the problem is the Location header, If I remove it I get the 302 status code through, but then how to tell the browser where to redirect to?

FYI 202 Accepted works good and probably 4XX too.

Thank you for the help!!

from aws-lambda-go.

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.