-
-
Save hasantayyar/261612430b5eddebd0c71ebcade37107 to your computer and use it in GitHub Desktop.
AWS Lambda function for Mailchimp list subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API_KEY='xxxxxxxxxxxxxxxxxxx-us1' | |
LIST_ID=12033101ax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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