Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

**Invoking a Function in the console returns this error in the console:
Error: Cannot find module '@sendgrid/mail'
In the output:
The function did not initialize properly.
The function was deployed from my local machine using:
doctl serverless deploy . --remote-build
This is the package.json file:
{
"name": "my-func-name",
"version": "1.0.0",
"description": "My func desc",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Mor Sagmon",
"license": "ISC",
"dependencies": {
"@sendgrid/mail": "^7.7.0",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2"
}
}
And this is the index.js file:
const sgMail = require('@sendgrid/mail');
// Assuming SENDGRID_API_KEY and SENDER_EMAIL are set as environment variables
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
async function main(args) {
const { to, templateId, dynamicData, unsubscribeGroupId, emergencyByPass } = args;
// Default response
let response = { "body": "Invalid request payload" };
// Validate the request payload
if (!to || !templateId || !dynamicData) {
return response;
}
// Construct the email object
const msg = {
to: to,
from: process.env.SENDER_EMAIL,
template_id: templateId,
dynamic_template_data: dynamicData,
mail_settings: { bypass_list_management: { enable: emergencyByPass } },
...(unsubscribeGroupId ? { asm: { group_id: unsubscribeGroupId } } : {}),
};
try {
// Send the email using SendGrid
await sgMail.send(msg);
response.body = { message: 'Email sent successfully' };
} catch (error) {
console.error(error);
response = { "body": { "error": 'Failed to send email', details: error.message } };
}
return response;
}
And the project.yml file:
parameters: {}
environment: {}
packages:
- name: app
shared: false
environment: {}
parameters: {}
annotations: {}
functions:
- name: security
binary: false
main: ""
runtime: nodejs:18
web: true
webSecure: false
parameters: {}
environment: {}
annotations: {}
limits: {
timeout: 3000
}
- name: send-email
binary: false
main: ""
runtime: nodejs:18
web: true
webSecure: false
parameters: {}
environment: {}
annotations: {}
limits: {
timeout: 8000
}
What am I missing here?
Rory McEwan
Anjanesh Lekshminarayanan
182d09356ab94d3893ddfaca4f0270
Prashant Kumbhat
kprichard
e452769e8f30404d81a3bc803143f4
robert
Eleanor
GamesmenJordan