Docs Menu
Docs Home
/ /
Atlas App Services
/ /

Replace Services with npm Modules

On this page

  • Overview
  • HTTP Service
  • node-fetch
  • axios
  • Twilio Service
  • AWS Service
  • S3
  • Kinesis
  • Lambda
  • SES

You should migrate deprecated third-party service integrations to use the corresponding official libraries available from npm. The sections later on this page contain details and examples for each service.

To migrate from a deprecated service:

  1. Add a library for the service from npm to your app.

  2. Import the library in your functions. Replace any calls to the built-in service actions with calls to the corresponding methods in the imported library.

  3. If the service has webhooks, convert them to HTTPS endpoints.

Replace HTTP requests sent through an HTTP Service client with calls to an HTTP library like node-fetch or axios.

npm i node-fetch@^2

Important

Atlas App Services does not support v3 of node-fetch. Use v2 instead.

Before
exports = async function() {
const http = context.services.get("myHttp");
const response = await http.get({
url: "https://www.example.com",
headers: { "Content-Type": [ "application/json" ] }
})
return response.body.text()
}
After (node-fetch)
exports = async function() {
const fetch = require("node-fetch"); // require calls must be in exports function
const response = await fetch("https://www.example.com", {
method: "GET",
headers: { "Content-Type": "application/json" }
})
return response.text()
}
npm i axios
Before
exports = async function() {
const http = context.services.get("myHttp");
const response = await http.get({
url: "https://www.example.com",
headers: { "Content-Type": [ "application/json" ] }
})
return response.body.text()
}
After (axios)
exports = async function() {
const axios = require("axios"); // require calls must be in exports function
const response = await axios.get("https://www.example.com", {
headers: { "Content-Type": "application/json" }
})
return response.data
}

Replace calls through a Twilio Service client with calls to the official Twilio Node Helper Library.

npm i twilio

To authenticate Twilio requests, store your Account SID and Auth Token as values. You can then access them within functions and pass them to the SDK.

Before
exports = async function() {
const twilio = context.services.get("myTwilio");
twilio.send({
to: "+15558675309",
from: "+15551234567",
body: "Hello from App Services!",
});
}
After
exports = async function() {
// Note: require calls must be in the exported function
const twilio = require('twilio')(
// Your Account SID and Auth Token from https://www.twilio.com/console
// Specify the same Twilio credentials as the service configuration
context.values.get("TwilioAccountSID"),
context.values.get("TwilioAuthToken"),
)
await twilio.messages.create({
to: "+15558675309",
from: "+15551234567",
body: "Hello from App Services!",
})
}

Replace calls through an AWS Service client with calls to the official AWS JavaScript SDK.

npm i aws-sdk

Important

App Services does not yet support version 3 of the AWS SDK. Use the version 2 SDK to replace the deprecated AWS Service in your functions.

To authenticate AWS requests, store your Access Key ID and Secret Access Key as values. You can then access them within functions and pass them to the SDK.

Before
exports = async function() {
const s3 = context.services.get("myAWS").s3("us-east-1");
const putResult = await s3.PutObject({
Bucket: "bucketName",
Key: "keyName",
Body: EJSON.stringify({ hello: "world" }),
});
const getResult = await s3.GetObject({
Bucket: "bucketName",
Key: "keyName",
});
}
After
exports = async function() {
const S3 = require('aws-sdk/clients/s3'); // require calls must be in exports function
const s3 = new S3({
accessKeyId: context.values.get("awsAccessKeyId"),
secretAccessKey: context.values.get("awsSecretAccessKey"),
region: "us-east-1",
});
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property
const putResult = await s3.putObject({
Bucket: "bucketName",
Key: "keyName",
Body: EJSON.stringify({ hello: "world" }),
}).promise();
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getObject-property
const getResult = await s3.getObject({
Bucket: "bucketName",
Key: "keyName",
}).promise();
}
Before
exports = async function() {
const kinesis = context.services.get("myAWS").kinesis("us-east-1");
const putResult = await kinesis.PutRecord({
Data: EJSON.stringify({ hello: "world" }),
StreamName: "myStream",
PartitionKey: "myPartition",
});
}
After
exports = async function() {
const Kinesis = require('aws-sdk/clients/kinesis'); // require calls must be in exports function
const kinesis = new Kinesis({
accessKeyId: context.values.get("awsAccessKeyId"),
secretAccessKey: context.values.get("awsSecretAccessKey"),
region: "us-east-1",
});
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Kinesis.html#putRecord-property
const putResult = await kinesis.putRecord({
Data: EJSON.stringify({ hello: "world" }),
StreamName: "myStream",
PartitionKey: "myPartition",
}).promise();
}
Before
exports = async function() {
const lambda = context.services.get('MyAwsService').lambda("us-east-1");
const invokeResult = await lambda.Invoke({
FunctionName: "myLambdaFunction",
Payload: EJSON.stringify({ hello: "world" }),
});
};
After
exports = async function() {
const Lambda = require('aws-sdk/clients/lambda'); // require calls must be in exports function
const lambda = new Lambda({
accessKeyId: context.values.get("awsAccessKeyId"),
secretAccessKey: context.values.get("awsSecretAccessKey"),
region: "us-east-1",
});
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property
const invokeResult = await lambda.invoke({
FunctionName: "myLambdaFunction",
Payload: EJSON.stringify({ hello: "world" }),
}).promise();
}
Before
exports = async function() {
const ses = context.services.get('MyAwsService').ses("us-east-1");
const sendResult = await ses.SendEmail({
Source: "sender@example.com",
Destination: { ToAddresses: ["receiver@example.com"] },
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: `This is a message from user ${context.user.id} sent through AWS SES`
}
},
Subject: {
Charset: "UTF-8",
Data: "Test Email Please Ignore"
},
},
});
};
After
exports = async function() {
const SES = require('aws-sdk/clients/ses'); // require calls must be in exports function
const ses = new SES({
accessKeyId: context.values.get("awsAccessKeyId"),
secretAccessKey: context.values.get("awsSecretAccessKey"),
region: "us-east-1",
});
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendEmail-property
const sendResult = await ses.sendEmail({
Source: "sender@example.com",
Destination: { ToAddresses: ["receiver@example.com"] },
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: `This is a message from user ${context.user.id} sent through AWS SES`
}
},
Subject: {
Charset: "UTF-8",
Data: "Test Email Please Ignore"
},
},
}).promise();
}

Back

Third-Party Services [Deprecated]