Skip to content

Instantly share code, notes, and snippets.

@nmagee
Last active November 11, 2021 21:22
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 nmagee/9f0651ae67320b31db4db8b9f9cfbf5e to your computer and use it in GitHub Desktop.
Save nmagee/9f0651ae67320b31db4db8b9f9cfbf5e to your computer and use it in GitHub Desktop.
PA Submission form for S3+CloudFront
<!DOCTYPE html>
<html>
<head>
<title>CS4740 - CloudFront+SNS+Lambda+SNS+Dynamo Application</title>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.780.0.min.js"></script>
<link href="https://getbootstrap.com/docs/4.5/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<script type="text/javascript">
function publish() {
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'us-east-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'ENTER-YOUR-COGNITO-IDENTITY-POOL-HERE',
});
// set up the sns client
var sns = new AWS.SNS();
// get the input value
var inputVal = document.getElementById("filler").value;
var params = {
Message: inputVal,
TopicArn: 'ENTER-YOUR-SNS-ARN-HERE'
};
sns.publish(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
var x = document.getElementById("publish");
var y = document.getElementById("thanks");
y.style.display = "block"; // show things after submission
x.style.display = "none"; // hide things after submission
}
</script>
<div style="width:400px;margin:100px;border: solid 1px #ccc;padding:2rem;">
<div id="publish" class="form-group">
<h3>SNS Submission for PA3</h3>
<label for="filler">Submit a random string:</label>
<input class="form-control" type="text" style="font-size:16px;padding:4px;" id="filler" /> <br />
<button id="submit-button" onclick="publish()" class="btn btn-success">Send to SNS</button>
</div>
<div class="form-group" id="thanks" style="display:none;">
<h3>Thank you for submitting</h3>
<a href="/">Retry</a>
</div>
</div>
</body>
</html>
@nmagee
Copy link
Author

nmagee commented Oct 29, 2020

Update lines 15 and 24 appropriately with your own environment values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment