Created
January 27, 2017 03:06
-
-
Save lukewduncan/cb2f15e260469f125c48cdc6c470d98a to your computer and use it in GitHub Desktop.
Client Side Lambda Submission
This file contains hidden or 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
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