AWS Lambda in Action: Event-driven serverless applications by Danilo Poccia

AWS Lambda in Action: Event-driven serverless applications by Danilo Poccia

Author:Danilo Poccia
Language: eng
Format: mobi, epub
Publisher: Manning Publications Co.
Published: 2019-01-31T23:00:00+00:00


Exercise

Add a name field to the Sign Up page and have the name stored on the DynamoDB table and in the validation email.

* * *

Tip

In Amazon DynamoDB, you need to specify only the primary key (the email in this case), and you can add different attributes in any item of the table. As a consequence, no changes in the IAM role used by the Lambda function are required.

* * *

Solution

To add a name, you need to change the HTML page (signUp.html), the client-side JavaScript file (signUp.js), and the Lambda function (createUser). A possible solution is presented in bold in the following listings, with the changes compared to the standard implementation.

signUpWithName.html (Sign Up page)

<html>

<head>

<title>Sign Up - Sample Authentication Service</title>

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.3.16.min.js"></script>

</head>

<body>

<h2>Sample Authentication Service</h2>

<h1>Sign Up</h1>

<form role="form" id="signup-form">

<div>

<label for="email">Email:</label>

<input type="email" id="email">

</div>

<div>

<label for="name">Email:</label>

<input type="text" id="name">

</div>

<div>

<label for="password">Password:</label>

<input type="password" id="password">

</div>

<div>

<label for="password">Verify Password:</label>

<input type="password" id="verify-password">

</div>

<button type="submit" id="signup-button">Sign Up</button>

</form>

<div id="result">

</div>

<a href="index.html">Back</a>

<script src="js/signUp.js"></script>

</body>

</html>

signUpWithName.js (JavaScript in the browser)

AWS.config.region = '<REGION>';

AWS.config.credentials = new AWS.CognitoIdentityCredentials({

IdentityPoolId: '<IDENTITY_POOL_ID>'

});



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.