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

Cannot load SDK into Google Apps Script #620

Closed
clemesha opened this issue Jun 4, 2015 · 10 comments
Closed

Cannot load SDK into Google Apps Script #620

clemesha opened this issue Jun 4, 2015 · 10 comments
Labels
guidance Question that needs advice or information.

Comments

@clemesha
Copy link

clemesha commented Jun 4, 2015

Hi,

I'm currently writing a simple service using https://developers.google.com/apps-script/
and I cannot get the SDK to load. I'm currently working with aws-sdk-2.1.32.

I've followed these steps:
http://googleappsdeveloper.blogspot.com/2012/11/using-open-source-libraries-in-apps.html
and still haven't got it to work.
I have tested the above method to load 'underscore.js', and that is working.

I can provide any other details or run any tests, just let me know.
Thank you.

@AdityaManohar
Copy link
Contributor

Can you explain what you are trying to do? I am able to include the SDK as a script tag directly on a html partial and use it in that partial page.

screen shot 2015-06-05 at 11 24 12 am

@clemesha
Copy link
Author

clemesha commented Jun 5, 2015

Hi, thanks for the response. I'm trying to use the AWS SDK as a library. See attached screenshot of using underscore.js and moment.js vs the AWS SDK.
screen shot 2015-06-05 at 2 52 58 pm

@AdityaManohar
Copy link
Contributor

The AWS SDK distributable relies on the existence of the window object. As I understand, Google Apps Script explicitly disallows any global access. I would recommend using an HTML partial with script tag. This way, you have access to the Google Apps Script libraries as well as the AWS SDK. You will even be able to pass data from your AWS resources into Google Apps.

Let me know if this helps.

@clemesha
Copy link
Author

clemesha commented Jun 8, 2015

I'm looking to just create a stand-alone Google Apps Script (GAS) that uses the built-in GAS "Time-driven" Events trigger.
In that stand-alone script I'm reading in emails from Gmail, then I hope to use the AWS SDK to trigger AWS Lambda functions, post data to S3, etc.

Let me know if this is possible, or if there are work-arounds to deal with the lack on the window object.
Thanks again.

@lsegal
Copy link
Contributor

lsegal commented Jun 8, 2015

Let me know if this is possible, or if there are work-arounds to deal with the lack on the window object.

It seems like the article you posted provides a number of workaround to include libraries in your code:

The simplest way to include the Underscore library in a project would be to paste its source code directly into your script

And also:

Packaging a JavaScript library like Underscore as an Apps Script library is possible, but requires some helper functions to work correctly.

Did you try either of these methods? Note that loading the AWS SDK should be equivalent to the methodology required to load Underscore that is described in that post. Specifically, both libraries rely on a global variable attached to window. Basically, you should be able to use the same logic that got underscore working for you by doing the same for the AWS variable instead of _. There should be no fundamental difference between these two libraries from the perspective of GAS.

It's hard for us to know what exactly is not working without seeing code. If you're still having trouble, it would help if you showed the code that you are using to load both Underscore and the AWS SDK in your application.

Hope that helps.

@lsegal
Copy link
Contributor

lsegal commented Jun 8, 2015

@clemesha I gave this a shot and was able to load the SDK with minimal adjustment to the aws-sdk.js file:

(function(){var window = {};

// PASTE THE AWS SDK CODE HERE

;this.AWS = window.AWS;}).call(this);

The AWS variable was made available to my script using this method. Seems like Google App Script expects globals to be written to this in order to be exported.

Note that although the SDK might "load", there is no guarantee that the SDK will function correctly, as it does depend on other properties exported in your JavaScript environment (like XMLHttpRequest). It does look like GAS provides a non-standard JavaScript environment that is currently not natively supported by the SDK. Following the suggestion by @AdityaManohar to run inside of an HTML partial and run it in EMULATED mode might be a better approach than trying to load it natively.

Hope that helps!

@clemesha
Copy link
Author

clemesha commented Jun 8, 2015

Ok, thank you for the very helpful updates! I just now tried what you suggested,
and things did get further, but as you also mentioned, there's other dependancies it relies on,
see attached screenshot of current test. Are these unfixable issues? Thanks again.
screen shot 2015-06-08 at 1 38 00 am

@lsegal
Copy link
Contributor

lsegal commented Jun 8, 2015

Yes, these are unlikely to have a workaround. See the second paragraph in my last response. Most notably, GAS has no native support for XHR, which is integral to the correct functioning of the SDK.

@clemesha
Copy link
Author

clemesha commented Jun 8, 2015

Ok, understood. Thanks again @AdityaManohar and @lsegal !

@clemesha clemesha closed this as completed Jun 8, 2015
@srchase srchase added the guidance Question that needs advice or information. label Dec 24, 2018
@lock
Copy link

lock bot commented Sep 29, 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 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

4 participants