Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS Lambda function for Mailchimp list subscription
API_KEY='xxxxxxxxxxxxxxxxxxx-us1'
LIST_ID=12033101ax
require('dotenv').load();
var Mailchimp = require('mailchimp-api-v3');
// mailchimp environment variables
var API_KEY = process.env.API_KEY,
LIST_ID = process.env.LIST_ID;
// function for subscribing a user
function addToList(emailAddress) {
var mailchimp = new Mailchimp(API_KEY);
mailchimp.request({
method : 'post',
path : '/lists/' + LIST_ID + '/members',
body : {
email_address : emailAddress,
status : 'subscribed'
}
}).then(function(results) {
console.log(results);
})
.catch(function (err) {
console.log(err);
});
}
exports.handler = function(event, context, callback) {
var emailAddress = event.email;
console.log(event.email);
addToList(emailAddress);
}
{
"name": "mailchimp-lambda-subscription",
"version": "1.0.0",
"description": "A Lambda function to create a subscription to a Mailchimp List",
"main": "index.js",
"scripts": {
"zip": "zip -r mailchimp-lambda.zip .env index.js node_modules/"
},
"author": "Luke Duncan",
"license": "MIT",
"dependencies": {
"mailchimp-api-v3": "*"
},
"repository": {
"type": "git"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.