DEV Community

Discussion on: Using Netlify lambda functions to send emails from a GatsbyJS site

Collapse
 
miguelmota profile image
Miguel Mota • Edited

You can move the environment variable code to outside the handler since there's no need to re-set the sendgrid config on every invocation.

const sgMail = require('@sendgrid/mail')

const { SENDGRID_API_KEY, SENDGRID_TO_EMAIL } = process.env
sgMail.setApiKey(SENDGRID_API_KEY)

exports.handler =  async (event, context, callback) => {
 // ..
}
Collapse
 
char_bone profile image
Charlotte

Great catch, thank you! I'll get that updated :)