dxdc / aws-sdk-google-apps Goto Github PK
View Code? Open in Web Editor NEWNative Google Apps Script support for Amazon AWS SDK for JavaScript
License: MIT License
Native Google Apps Script support for Amazon AWS SDK for JavaScript
License: MIT License
I've rebuilt the sdk to add athena, pushed it up to google with clasp & am referencing it from my script - all seemingly hunky dory.
But when I attempt to use the athena SDK I get an error "Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported"
I can see how this is generated looking at the un-minimised code on my machine.
I can also see it in the minimal code in https://github.com/dxdc/aws-sdk-google-apps/blob/master/dist/AwsSdk.js
(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(){if(!getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return getRandomValues(rnds8)};var getRandomValues="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),rnds8=new Uint8Array(16)},{}],120:[function(require,module,exports){"use strict";function f(s,x,y,z){switch(s){case 0:return x&y^~x&z;case 1:return x^y^z;case 2:return x&y^x&z^y&z;case 3:return x^y^z}}function ROTL(x,n){return x<<n|x>>>32-n}Object.defineProperty(exports,
But the error doesn't seem to happen when I use the original script referenced in your README.
I managed to create a separate JS repository to be able to query Athena (using the v3 of the AWS SDK).
I'm not a javascript developer and I'm having trouble importing this new library into Google Apps Script. Could you guys help me out with any tips or reference materials?
Or maybe help me out incorporating my new functions into this brilliant and life-saving repo?
Here's what I came up with:
const { AthenaClient, StartQueryExecutionCommand, GetQueryExecutionCommand, GetQueryResultsCommand } = require('@aws-sdk/client-athena');
async function runAthenaQuery(athenaClient, database, query, outputLocation) {
const queryExecutionParams = {
QueryString: query,
QueryExecutionContext: {
Database: database,
},
ResultConfiguration: {
OutputLocation: outputLocation,
},
};
const startQueryExecutionCommand = new StartQueryExecutionCommand(queryExecutionParams);
try {
const queryExecutionResponse = await athenaClient.send(startQueryExecutionCommand);
const queryExecutionId = queryExecutionResponse.QueryExecutionId;
console.log("Query submitted. Execution ID:", queryExecutionId);
return queryExecutionId;
} catch (error) {
console.error("Error executing Athena query:", error);
throw error;
}
}
function getQueryResultsWithPolling(athenaClient, queryId) {
return new Promise((resolve, reject) => {
const interval = setInterval(() => {
const queryExecutionParams = { QueryExecutionId: queryId };
const getQueryExecutionCommand = new GetQueryExecutionCommand(queryExecutionParams);
athenaClient.send(getQueryExecutionCommand)
.then((response) => {
const status = response.QueryExecution.Status.State;
console.log(`Query execution status: ${status}`);
if (status === 'SUCCEEDED') {
clearInterval(interval);
const getQueryResultsParams = { QueryExecutionId: queryId };
const getQueryResultsCommand = new GetQueryResultsCommand(getQueryResultsParams);
return athenaClient.send(getQueryResultsCommand);
} else if (status === 'FAILED' || status === 'CANCELLED') {
clearInterval(interval);
reject(new Error(`Query execution failed or cancelled. Status: ${status}`));
}
})
.then((resultResponse) => {
resolve(resultResponse);
})
.catch((error) => {
clearInterval(interval);
reject(error);
});
}, 2000);
});
}
function executeAthenaQuery(database, query, outputLocation, awsRegion, awsAccessKeyId, awsSecretAccessKey) {
const awsCredentials = {
accessKeyId: awsAccessKeyId,
secretAccessKey: awsSecretAccessKey,
};
const athena = new AthenaClient({
region: awsRegion,
credentials: awsCredentials,
});
return new Promise(async (resolve, reject) => {
try {
const queryId = await runAthenaQuery(athena, database, query, outputLocation, awsRegion, awsAccessKeyId, awsSecretAccessKey);
console.log('Query ID:', queryId);
const queryResults = await getQueryResultsWithPolling(athena, queryId);
console.log('Query Results:', queryResults);
resolve(queryResults);
} catch (error) {
console.error('Error:', error);
reject(error);
}
});
}
Thanks a ton
I am trying to get cloudformation outputs, but it seems CloudFormation
does not work.
I tested other services such as s3 and it works.
Also, I tested both versions: as library and copying the dist files. In both cases happen the same.
Here is my code:
function syncCfnOutputs() {
AWSSDK.initConfig(AWS_CONFIG);
const client = new AWSSDK.AWS.CloudFormation();
client.listExports({}, (error, data) => {
if (error) {
throw `Error listing CloudFormation exports: ${error.message}`;
} else {
Logger.log(data.Exports)
}
})
}
Got this error:
TypeError: AWSSDK.AWS.CloudFormation is not a constructor
Any idea why or how can I fix it?
Hi,
I found your component aws-sdk-google-apps on github and it's awesome !
Thanks a lot for this job !
I added it as a library on my google script, but I don't know how to use it in my script.
I just need to use it to send emails with SES API, but I haven't found on Internet how to do that in a google app script.
With the AWS Stack, I'm a newby and I really don't know how to use it from google app script, how to put my credentials, and to call the SES function to send emails.
If you know all this stuff, I would be very grateful if you can send me some examples.
Thank you so much
Thomas
Came across your repo after some searching and I tried AWSLIB.AWS.EC2
but it looks like EC2 is not available in the standard library
It looks like onyl a few services are aded by default.
In your library - maybe it would be more flexible to add all the services ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.