Beruflich Dokumente
Kultur Dokumente
arn:aws:sns:us-east-1:978742500202:HighAccountBalanceAlertSNSTopic
===================================================================================
===============================
===================================================================================
===============================
1. Locate the section you need. Each section in this file matches a section in the
lab instructions.
2. Replace items in angle brackets - < > - with appropriate values. For example, in
this command you would replace the value - <JobFlowID> - (including the angle
brackets) with the parameter indicated in the lab instructions:
elastic-mapreduce --list <JobFlowID>. You can also use find and replace to change
bracketed parameters in bulk.
3. Do NOT enable the Word Wrap feature in Windows Notepad or the text editor you
use to view this file.
===================================================================================
===============================
Task 3.1: Create Lambda Function to Process Transactions Text File
===================================================================================
===============================
3.1.15 Copy and paste the code for the Lambda function.
import json
import urllib
import boto3
import csv
print('Loading function')
customerTableName = 'Customer'
transactionsTableName = 'Transactions'
s3 = boto3.resource('s3')
dynamodb = boto3.resource('dynamodb')
customerTable = dynamodb.Table(customerTableName);
transactionsTable = dynamodb.Table(transactionsTableName);
return "done"
===================================================================================
===============================
Task 3.2: Create Lambda Function to Calculate Transaction Totals and Notify About
High Account Balances
===================================================================================
===============================
3.2.16 Copy and paste the code for the Lambda function.
import json
import boto3
print('Loading function')
dynamodb = boto3.resource('dynamodb')
transactionTotalTableName = 'TransactionTotal'
transactionsTotalTable = dynamodb.Table(transactionTotalTableName);
sns = boto3.client('sns')
response = transactionsTotalTable.update_item(
Key={
'CustomerId': customerId
},
UpdateExpression="add accountBalance :val",
ExpressionAttributeValues={
':val': transactionAmount
},
ReturnValues="UPDATED_NEW"
)
print("Added transaction to account balance in TransactionTotal table")
latestAccountBalance = response['Attributes']['accountBalance']
print("Latest account balance: ".format(latestAccountBalance))
===================================================================================
===============================
Copyright 2016 Amazon Web Services, Inc. or its affiliates. All rights reserved.