-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support using the SDK with browserify #383
Comments
@konklone unfortunately it would be difficult to enable browserifying the npm package of the SDK. Because of the way we dynamically load service models (via dynamic require), the SDK is actually not compatible with pure browserify-- we actually build the hosted version with a script that manually adds in service models after browserify runs (see here). The error you are seeing when running browserify on the package would actually be the least of your problems-- once you get past that one you will run into many more related to services. We're open to suggestions on how to make it more browserify-friendly if you have any, but browserify doesn't handle dynamic requires, which we take advantage of in Node.js. At the end of the day you'll need to use a specially built version of the SDK, especially if you want to take advantage of services that are not part of the default hosted build / npm package. Note that it should be fairly easy to use browserify's multitude of options to work around this without changing the SDK. The following command worked for me: $ browserify -r ./aws.js:aws-sdk index.js Where index.js is: var AWS = require('aws-sdk');
var s3 = new AWS.S3(); And aws.js is additionally placed in your project to load the SDK with the following single line: module.exports = window.AWS; You still won't get the SDK to use Stream objects though, as we don't use or support them in the browser. I haven't tested whether the SDK whether this affects the usage of |
OK, that works for me too. Then, could this issue be resolved by adding a section to the docs about using browserify with AWS? Also, would it be possible to add a line to the resulting build that checks for the existence of
That's all right - s3-upload-stream presents a stream input interface, with which it builds little 5MB+ buffers that it hands off to the AWS SDK to perform parts of multipart uploads. So it basically acts as the Stream interface that this SDK doesn't support in-browser. The important part of s3-upload-stream is that it can have things |
Unfortunately this is not that simple to do. You would still need to stub out the $ browserify -r ./path/to/aws-sdk.js:aws-sdk index.js But I'm currently getting resolution errors from browserify:
If you have any insights on getting this to work, I'm all ears. Right now I think the best solution is to provide the separate On a sidenote, I agree that we can improve our docs to describe this use case more clearly. |
Works without any custom code. Note that by default only the default services will be included in the browserified aws-sdk build. In order to build other services, you can pass the `AWS_SERVICES` environment variable to browserify: AWS_SERVICES=s3,ec2,dynamodb browserify myscript.js > out.js The above command includes only Amazon S3, Amazon EC2, and Amazon DynamoDB in the generated SDK. You can use "all" to include all services. See #383
@konklone I have a WIP branch (npm-browserifiable) that allows you to call Take a look at the branch and let me know if this works for you. You can test it out by using:
|
@lsegal I was getting a
It looks like it was caused by some missing files - the
Thanks for working on this!! |
@mablack this was actually a great catch! Thanks! Avoided a potentially botched release :) That was related to the way we recently changed filenames in #379. We try to glob on the .normal. files but those files are excluded from npm installs, so this would have broken the package! Just pushed a fix to master and merged it over into the browserifiable branch. Try now? |
@lsegal all good now!! :) |
Sorry I didn't have a chance to test this, but thank you @lsegal for making this happen in spite of the challenges! I'll be un-freezing my |
Release is out. You should now be able to use this from a regular npm install. |
Great, just switched to the latest release - thanks again for working on this @lsegal! |
@lsegal if (file.match(/\/lib\/browser\.js$/)) { // dirty fix: /[\/\\]lib[\/\\]browser\.js$/
stream.push(license);
var src = collector(process.env.AWS_SERVICES); |
@lsegal I'm working on using browserify in nodejs, with the output being targeted at a lambda function. FWIW I'm doing this as part of my work on the new JAWS project - essentially making it easier to use Lambda/api gateway etc. Anyways, we'd like to use browserify to keep the footprint small (to combat the well documented cold start problems). We also want to bundle aws-sdk for node so we can target specific versions and not rely on what is exposed in the lambda nodejs runtime. We are concerned with the dynamic require brought up in this issue, however it looks like you have it solved in >= v2.0.20 I'm struggling with when its necessary to use the |
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. |
Right now, the AWS SDK for JavaScript is usable by browserify, but with constraints:
From this place:
require()
calls.The fact that I can get it working via browserify like this suggests it shouldn't be a huge lift for the project to support browserify via npm.
The benefit of using it via browserify, compared to using it in a more traditional way, is that it makes it possible to combine the AWS SDK with other Node-packaged modules in npm (including those designed to work with this library in Node-land).
In my case, I'm connecting
filereader-stream
' tos3-upload-stream
in the browser to pipe data from disk directly into S3 using the Multipart Upload API. Stream syntax is incredibly helpful at gluing complicated workflows together in a simple way, and I wouldn't be able to pull this off without using browserify.The text was updated successfully, but these errors were encountered: