Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda FunctionZip doesn't support a stream object #552

Closed
rclark opened this issue Mar 29, 2015 · 5 comments · Fixed by #563
Closed

Lambda FunctionZip doesn't support a stream object #552

rclark opened this issue Mar 29, 2015 · 5 comments · Fixed by #563

Comments

@rclark
Copy link
Contributor

rclark commented Mar 29, 2015

According to the documentation http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#uploadFunction-property

FunctionZip: new Buffer('...') || 'STRING_VALUE' || streamObject, /* required */

This works fine as long as I provide a buffer object, but if I provide a stream (via fs.createReadStream), I get the following error:

TypeError: Not a string or buffer
        at Hash.update (crypto.js:240:17)
        at Object.util.crypto.hash (/home/travis/build/mapbox/streambot/node_modules/aws-sdk/lib/util.js:507:24)
        at Object.sha256 (/home/travis/build/mapbox/streambot/node_modules/aws-sdk/lib/util.js:461:26)
        at V4.hash [as hexEncodedHash] (/home/travis/build/mapbox/streambot/node_modules/aws-sdk/lib/signers/v4.js:172:28)
        at V4.hexEncodedBodyHash (/home/travis/build/mapbox/streambot/node_modules/aws-sdk/lib/signers/v4.js:181:19)
        at V4.canonicalString (/home/travis/build/mapbox/streambot/node_modules/aws-sdk/lib/signers/v4.js:126:21)
        at V4.stringToSign (/home/travis/build/mapbox/streambot/node_modules/aws-sdk/lib/signers/v4.js:113:41)
        at V4.signature (/home/travis/build/mapbox/streambot/node_modules/aws-sdk/lib/signers/v4.js:105:43)
        at V4.authorization (/home/travis/build/mapbox/streambot/node_modules/aws-sdk/lib/signers/v4.js:82:36)
        at V4.addAuthorization (/home/travis/build/mapbox/streambot/node_modules/aws-sdk/lib/signers/v4.js:35:12)
@lsegal
Copy link
Contributor

lsegal commented Mar 29, 2015

The logic S3 uses to sign payloads should probably be moved directly into the V4 signer so all services can make use of this logic.

A temporary workaround would be to do the following:

var lambda = new AWS.Lambda();
var params = { ... };
lambda.uploadFunction(params).
    on('build', AWS.S3.prototype.computeSha256).
    send(function(data, err) {
  console.log(data, err);
});

Let me know if that works for you. Note that it uses a private API, so it should just be a workaround, not permanent code.

Note also that stream support will still only work with rewindable/seekable streams (namely file objects), as we must be able to seek the stream to compute a checksum of the body prior to sending.

@rclark
Copy link
Contributor Author

rclark commented Mar 29, 2015

In my situation today using a buffer is totally reasonable (although #551 can be a problem with larger buffers), but thanks for the workaround. You suspect this logic will move into the v4 signer relatively soon?

@lsegal
Copy link
Contributor

lsegal commented Mar 29, 2015

@rclark yea this should be a fairly easy refactor. I'm just not near my dev machine right now, but it should get looked at this week.

@lsegal
Copy link
Contributor

lsegal commented Mar 29, 2015

/cc @AdityaManohar

@lock
Copy link

lock bot commented Sep 30, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants