We have a aws lambda function that processes some data and incase there is an error it sends out an email.
We experienced a surge of email from the lambda function so we changed the script and disabled the part where it sends email. Unfortunately we still see the emails comming in.
So we deleted the function and we still keep receiving the error emails.
How can the lambda function still be running. Would i be experiencing charges since the function is running.
John
Related
My Sheet-bound script is sending an email using MailApp.sendEmail.
The emails are always sent 'from' my own Gmail account. This project is for a customer, and I need his email to be the 'from' on these emails.
Reading similar questions I learn that the I only have flexibility in changing the name and replyTo address, using the advanced options of MailApp.sendEmail. However, the email address is still mine and Google doesn't offer any control over that.
I'm not familiar enough with all of the Google services and options to find the best way to do this. My customer does have a Google Apps for Business, but I don't.
Can I somehow create the email-sending function as a standalone script under his account, and somehow call it from the project under my account?
Any other ideas?
Thanks!
Emails are always sent from the account of the user that executes the script. In case the email is sent by a triggered function (installable triggers are the only ones that are able to send emails since it requires explicit authorization) then the email is sent from the account of the user that created the trigger (and authorized it).
In your case, it seems that the easier solution would be to ask your customer to execute the script himself and initiate all the triggers himself too.
If that should not be possible then you could indeed use a standalone script that would work as a kind of proxy, ie it would receive a request to send a message and actually send it from the customer account while returning an acknowledgement to your script.
But that's a bit tricky... the first solution is more elegant.
Edit :
I found the idea of sending emails through an independent script funny so I gave it a quick try and it seems to do the job pretty easily... test code below (this code should be deployed as a standalone app from your customer account) :
function doGet(e) {
Logger.log('e = e'+JSON.stringify(e));
if(e.parameter.recipient==null){return ContentService.createTextOutput("error, wrong request "+JSON.stringify(e)+"\n\n"+e.parameter.recipient+"\n\n"+e.parameter.subject+"\n\n"+e.parameter.body).setMimeType(ContentService.MimeType.TEXT)};
try{
MailApp.sendEmail(e.parameter.recipient, e.parameter.subject, e.parameter.body)
}catch(err){
return ContentService.createTextOutput('error : '+err).setMimeType(ContentService.MimeType.TEXT);
}
return ContentService.createTextOutput('mail successfully sent').setMimeType(ContentService.MimeType.TEXT);
}
note : the code below goes in your spreadsheet script, the doGet above is an standalone app running from your customer account.
function sendMail(recipient,subject,body){
var sent = UrlFetchApp.fetch("https://script.google.com/macros/s/---------------S381kO1Kqv61E/exec?recipient="+recipient+"&subject="+subject+"&body="+body);
Logger.log(sent);
}
function test(){
sendMail('recipient#gmail.com','test message','hello world')
}
I was able to send messages from my gmail account while being logged as a different user. (the url above is intentionally truncated, I don't want anyone to send email from my account ;-)
Is there a way to pass a value back to a HTML page while a server side function is running?
In the past when I was using the UI service, early in the function I would just create a label in the UI like:
app.createLabel('Working, hang on!');
And it would appear while the script was running, letting them know the script was running. When it got to certain parts of the script I would then be able to update/create a new message like:
app.createLabel('Halfway there, hold on.');
Or
app.createLabel('Fetched values, processing them');
etc., to tell them where we are if the script was running for a long time. An added bonus was that it could also update them on what direction the script was taking, so for example if a room booking script found that the first room was unavailable, it could pass a message back such as:
app.createLabel('First room was busy, checking other rooms');
And so on, and so forth.
Is there a way to do this with the HTML service? It seems my only options are success and failure handlers updating the HTML page when the function is complete, which don't seem to be what I want, as it's not a 'Real Time' message.
You can still use ui.alert() in sheets and docs, and sheets also has toast().
To keep the message within a sidebar or dialog that you've created using the HTML Service, you can set up a separate poller function on the client, to retrieve messages from the server every once in a while. Your long-running function could queue up a message via a function call on the server, which would be picked up by the poller on its next cycle, and displayed to the user.
See How to poll a Google Doc from an add-on for an example of a poller.
I use a very cool Google Script I found on Github (source: https://gist.github.com/beezly/9b2de3749d687fdbff3f) to fetch the temperature on my Nest thermostat and log it into a Google Spreadsheet.
It is working great when I run the script manually, but not when I use a time trigger to run it automatically.
When posting the credential to the API on this line:
Line 12: var response = JSON.parse(UrlFetchApp.fetch('https://home.nest.com/user/login', options).getContentText());
The exception raised is:
Request failed for https://home.nest.com/user/login returned code 429.
Truncated server response: Too many requests (use muteHttpExceptions
option to examine full response) (line 12, file "Code")
I suspect that I'm not the only one using the script, and the Google source IP used by the trigger has exceeded the limit of the Nest API.
Would you have any solution for me? I have considered using a Proxy server, but the UrlFetchApp.fetch function does not seem to accept it.
Thank you,
PF
I only ran into the "Too many requests" error during development when I was testing that same script. I was able to get this function to run hourly no problem, even every 5 minutes.
To get this script run as expected on a trigger just switch the getData() to a doGet(), publish it as a web app with anonymous access then create another function (i called it getData()) that makes a request to your published web app url (which invokes a doGet()), then just create your time-based trigger to run the new getData().
here's my version https://gist.github.com/jbutters/bece2fffe85080fe4314
I have a Google Apps Script which uses a JSON web API to get a list of StarCraft2 tournaments from a site (using UrlFetchApp) and create corresponding Google Calendar events in a variety of Calendars (one Calendar per region/league combination).
I have a trigger set to every 5 minutes, that emails me immediately on errors, and if the script completes normally and has added any events or run into any errors I caught, it emails me as well.
Most of the time, there are no changes necessary (I cache the JSON info using ScriptDb to avoid calling out to CalendarApp unless I need to) and the script is silent. However, overnight I received several emails which contained the messages:
The resource you requested could not be located. (line 154)
Service error: CalendarApp: Error body {font-family: arial,sans-serif}
G o o g l e Error Cannot access the calendar you requested (line 155)
TypeError: Cannot call method "getEvents" of null. (line 155)
Lines 154, 155 and 156 are:
var calendar = CalendarApp.getCalendarById(calendars[region][league]);
var events = calendar.getEvents(new Date(1900, 1, 1), new Date());
events.forEach(function (event) { event.deleteEvent(); });
At this point in the script I've already attempted to add any new events and I'm about to query each of my Calendars to delete any events which occurred in the past.
These errors appear to be an issue with the availability of CalendarApp, but the Dashboard does not indicate any issues with the service.
My project key is: MWhWmFSrL1dK3RJui6Aphb12cA4KNgw7R
I have many scripts that use CalendarApp and all of them have occasional errors in their execution, wether in manual mode or time triggered, it seems (but I know this is an empirical feeling) that this service is subject to errors when the traffic is too high or the internet connection is too slow (a few month ago my office had a very poor internet connection and the script used to generate a lot of errors -while it didn't when executed from home-, now that the situation is better the same script runs smoothly everywhere).
Anyway, whatever the real cause might be (and only a Google engineer could answer), the solution I used was to put the Calendar calls in a try-catch loop that tries the connection a few times and since then I have no error notification anymore.
On another script that I didn't change yet, I keep getting errors from time to time but since it doesn't concern critical information I don't really mind... note that I just checked right now and I haven't receive any notification for 5 days ! (must be a good season for calendars ;-)
I have some GAS currently being run off of a spreadsheet. They will eventually move to a published service, however, the current issue needs to be resolved first.
I'm running into an issue where a script that I've written, and other users have used in the past are receiving the Subject error message.
A new script I can run (but others cannot) has been taken down to a single test function
function hello()
{ Browser.msg("Hello There") }
This still generates the "You do not have authorization to perform that action."
My older script has had no script changes and now users receive the same error.
I hadn't updated the Sharing settings on my script. Maybe that's what Jan was referring to...
Thanks Jan !