Skip to content

Instantly share code, notes, and snippets.

@lukewduncan
Created January 27, 2017 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukewduncan/cb2f15e260469f125c48cdc6c470d98a to your computer and use it in GitHub Desktop.
Save lukewduncan/cb2f15e260469f125c48cdc6c470d98a to your computer and use it in GitHub Desktop.
Client Side Lambda Submission
function subscribeToList(email) {
var params = {
AccountId: "xxxxxxxxxxx", // your AWS user account ID
RoleArn: "arn:aws:iam::xxxxxxxxxxx:role/Cognito_mailchimpCognitoUnauth_Role", // your Cognito unauth role (it wil look something like this)
IdentityPoolId: "us-east-1:xxxxxxxxxxxxxxxxx" // the identity pool id found in Cognito
};
// set the Amazon Cognito region
AWS.config.region = 'us-east-1';
// initialize the Credentials object with our parameters
AWS.config.credentials = new AWS.CognitoIdentityCredentials(params);
// invoking the actual Lambda function
var lambda = new AWS.Lambda();
lambda.invoke({
FunctionName: 'mailchimpSubscribe', // your function name
LogType: "Tail",
InvocationType: "Event",
Payload: JSON.stringify({
"email": email
}) // how you send the email to the Lambda event
}, function(err, data){
if (err) {
console.log(err, err.stack);
} else {
console.log('Thanks! Your signed up to my email list on Mailchimp');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment