Skip to content

Unsupported content type: binary/octet-stream when using aws-sdk Lambda.invoke #591

Closed

Description

@jrmdayn

After generating a toy example using sam init and spinning a local lambda endpoint using sam local start-lambda, I get the following error when trying to invoke the lambda from node using aws-sdk. Say my lambda function is named: HelloWorldFunction. I have the following main.js file:

const AWS = require("aws-sdk");

const lambda = new AWS.Lambda({
  endpoint: "http://127.0.0.1:3001/",
  region: "NA"
});

lambda.invoke(
  {
    FunctionName: "HelloWorldFunction",
    Payload: JSON.stringify({})
  },
  (err, res) => {
    console.log("back with", err, res);
  }
);

When I call node main.js I get the following error:
UnsupportedMediaType: Unsupported content type: binary/octet-stream

If I don't pass a payload in the invoke object, I get a response.

Steps to reproduce the issue:

  1. sam init
  2. sam local start-lambda -t sam-app/template.yml
  3. node main.js

Observed result:
UnsupportedMediaType: Unsupported content type: binary/octet-stream

Expected result:
The response, with no error.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

Output of sam --version:
0.5.0

Activity

  1. jfuss commented on Jul 31, 2018

    @jfuss
    Contributor

    @jeremie-stratumn Thanks for the report. Looks like different SDKs send different headers, which I was not aware of. I was trying to get fancy here and constrain the request to be 'application/json'. It seems that as long as the request is json, it doesn't matter (I tried your example with invoke a deployed lambda function).

    I think we should just remove this header check. We are already checking to see if the request data is json.

    Would you be willing to contribute the fix (with updating all the respective tests)?

  2. jrmdayn commented on Aug 1, 2018

    @jrmdayn
    ContributorAuthor

    Thanks @jfuss for getting back to me on this. I would be glad to help! So it's just a matter of removing this check and fixing the tests right? I'll send you a PR.

    Cheers

  3. jfuss commented on Aug 1, 2018

    @jfuss
    Contributor

    @jeremie-stratumn That seems to be all. This will relate the checks we do and get us more inline with what the Lambda Service does.

    We should just update this functional test to pass, which should cover the use-case you ran into with the node sdk and help catch future regressions in the future.

    If you need help in some way, feel free to ping me on slack or the #samdev channel.

  4. jfuss commented on Aug 6, 2018

    @jfuss
    Contributor

    Waiting for release, updating labels.

    Thanks again @jeremie-stratumn for the PR :)

  5. added
    stage/waiting-for-release
    on Aug 6, 2018
  6. jrmdayn commented on Aug 7, 2018

    @jrmdayn
    ContributorAuthor

    No worries!

  7. jfuss commented on Aug 29, 2018

    @jfuss
    Contributor

    Closing this as it was released in 0.6.0

  8. removed
    stage/waiting-for-release
    on Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions