Task: Write to DynamoDB
In this task, we will modify code in Google Apps Script to write record all logins in a newly created DynamoDB table.
1. Create a table to hold the log.
- In DynamoDB, create a table as follow
- Table name: Session
- Partition key: email (string)
- Sort Key: start_time (number)
3. Modify the "record_login" function to appear as follows:
function record_login(email){const payload={"TableName": "session","Item": {"email": {"S": email},"start_time":{"N":Date.now().toString()},}}return dynamo(payload,"PutItem")}
4. Add a function to test the record_login function as follows:
function test_record_login(){console.log("at test_record_login")console.log(record_login("yourname@gmail.com"))}
5. Test the logging feature by executing the "test_record_login" function.
6. See that a record has been added to the "session" table in DynamoDB
7. Add a statement to the "login" function to record all system logins
- find the following comment:
// had a successful login, log it to dynamo (during workshop)
- Add the following line:
record_login(data.email)
8. Deploy your Google Apps Script
9. Copy the Deployment ID to the "config.js" file in VS Code
10. Verify that logins from the app are being recorded in DynamoDB