I am building Alexa Skill for Google calendar. The client side code works as expected on local machine because I can authenticate the local machine using the link. But, when I deploy the code on AWS Lambda there is no way that I can authenticate as I cannot input code via AWS console.
I am getting trouble in setting up authentication of Google Calendar API when deployed on AWS lambda.
This documentation doesn't help much to me Google Implementing Server Side Authentication
You should create a service account. Those are designed especially for server-to-server communication. Documentation can be found here: https://developers.google.com/identity/protocols/OAuth2ServiceAccount
The problems with the solutions from other answers are:
gcloud auth print-access-token
) expire. Since Lambdas are stateless, there's no way to store a token temporarily and refresh it when it's expired.I know this is late, but after struggling a lot with this problem, I found a solution. Do google auth with JWT
const {google} = require('googleapis');
const key ={
client_email: process.env.CLIENT_EMAIL,
private_key: process.env.PRIVATE_KEY,
}
const auth = new google.auth.JWT(
key.client_email,
null,
key.private_key,
["https://www.googleapis.com/auth/analytics.readonly"],
null
);
google.options({auth});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With