Пример #1
0
def connection():
    ACCOUNT_ID =
    IDENTITY_POOL_ID =
    ROLE_ARN =

    # Use cognito to get an identity.
    cognito = boto.connect_cognito_identity()
    cognito_id = cognito.get_id(ACCOUNT_ID, IDENTITY_POOL_ID)
    oidc = cognito.get_open_id_token(cognito_id['IdentityId'])

    # Further setup your STS using the code below
    sts = boto.connect_sts()
    assumedRoleObject = sts.assume_role_with_web_identity(ROLE_ARN, "XX", oidc['Token'])

    # Prepare DynamoDB client
    # Prepare DynamoDB client
    client_dynamo = boto.dynamodb2.connect_to_region(
        'us-east-1',
        aws_access_key_id=assumedRoleObject.credentials.access_key,
        aws_secret_access_key=assumedRoleObject.credentials.secret_key,
        security_token=assumedRoleObject.credentials.session_token)

    tables = client_dynamo.list_tables()
    dataTable = table_creation(tables, client_dynamo)
    return dataTable
Пример #2
0
 def setUp(self):
     self.cognito_identity = boto.connect_cognito_identity()
     self.cognito_sync = boto.connect_cognito_sync()
     self.identity_pool_name = 'myIdentityPool'
     response = self.cognito_identity.create_identity_pool(
         identity_pool_name=self.identity_pool_name,
         allow_unauthenticated_identities=False)
     self.identity_pool_id = response['IdentityPoolId']
Пример #3
0
 def setUp(self):
     self.cognito_identity = boto.connect_cognito_identity()
     self.cognito_sync = boto.connect_cognito_sync()
     self.identity_pool_name = 'myIdentityPool'
     response = self.cognito_identity.create_identity_pool(
         identity_pool_name=self.identity_pool_name,
         allow_unauthenticated_identities=False
     )
     self.identity_pool_id = response['IdentityPoolId']
Пример #4
0
import mraa
import time
import json


DYNAMO_TABLE_NAME = 'YOUR_TABLE_NAME'
KINESIS_STREAM_NAME = 'YOUR_KINESIS_STREAM_NAME'
ACCOUNT_ID = 'YOUR_ACCOUNT_ID'
IDENTITY_POOL_ID = 'YOUR_IDENTITY_POOL_ID'
ROLE_ARN = 'YOUR_ROLE_ARN'

#################################################
# Instantiate cognito and obtain security token #
#################################################
# Use cognito to get an identity.
cognito = boto.connect_cognito_identity()
cognito_id = cognito.get_id(ACCOUNT_ID, IDENTITY_POOL_ID)
oidc = cognito.get_open_id_token(cognito_id['IdentityId'])

# Further setup your STS using the code below
sts = boto.connect_sts()
assumedRoleObject = sts.assume_role_with_web_identity(ROLE_ARN, "XX", oidc['Token'])

# Connect to dynamoDB and kinesis
client_dynamo = boto.dynamodb2.connect_to_region(
	'us-east-1',
	aws_access_key_id=assumedRoleObject.credentials.access_key,
    aws_secret_access_key=assumedRoleObject.credentials.secret_key,
    security_token=assumedRoleObject.credentials.session_token)

client_kinesis = boto.connect_kinesis(
import boto.dynamodb2
import time
import json
import serial
import time
#import testdata
from boto.dynamodb2.fields import HashKey, RangeKey, KeysOnlyIndex, GlobalAllIndex
from boto.dynamodb2.types import NUMBER
from boto.dynamodb2.items import Item

ACCOUNT_ID = ''
IDENTITY_POOL_ID = ''
ROLE_ARN = ''

# Use cognito to get an identity.
cognito = boto.connect_cognito_identity()
cognito_id = cognito.get_id(ACCOUNT_ID, IDENTITY_POOL_ID)
oidc = cognito.get_open_id_token(cognito_id['IdentityId'])
 
# Further setup your STS using the code below
sts = boto.connect_sts()
assumedRoleObject = sts.assume_role_with_web_identity(ROLE_ARN, "XX", oidc['Token'])

DYNAMODB_TABLE_NAME = 'pingdata'
# Prepare DynamoDB client
client_dynamo = boto.dynamodb2.connect_to_region('us-east-1',aws_access_key_id=assumedRoleObject.credentials.access_key,aws_secret_access_key=assumedRoleObject.credentials.secret_key,security_token=assumedRoleObject.credentials.session_token)

KINESIS_STREAM_NAME = 'edisonDemoKinesis'
# Prepare Kinesis client
client_kinesis = boto.connect_kinesis(aws_access_key_id=assumedRoleObject.credentials.access_key,aws_secret_access_key=assumedRoleObject.credentials.secret_key,security_token=assumedRoleObject.credentials.session_token)
from boto import kinesis
class dynamoMethods:
    def __init__(self, dbName):
        self.table_dynamo = None
        ####################################################################
        # YOUR CODE HERE
        try:
            #1. create new table
            self.table_dynamo = #HINT: Table.create; #HINT 2: Use CUID as your hashkey
            print "New Table Created"
        except Exception as e:
            #2.table already exists, so get the table
            self.table_dynamo = #HINT: Remember to use "connection=client.dynamo"
            print "Table Already Exists"
        ####################################################################

    def dynamoAdd(self, cuid, name, password):
        ####################################################################
        # YOUR CODE HERE
        #1. Check table for entries that have the same CUID, if so, UPDATE (Don't delete)
        #2. Otherwise, create a new entry
        print "New entry created.\n"
        ####################################################################

    def dynamoDelete(self, cuid):
        ####################################################################
        # YOUR CODE HERE
        #1. Check table for entries that have the same CUID, if so, DELETE
        ####################################################################

    def dynamoViewAll(self):
        ####################################################################
        string_db = "CUID: NAME\n"
        print string_db
        #1. Get all entries in the table
        #2. Print the CUID: NAME for each entry
        ####################################################################
        

####################################################################
# DON'T MODIFY BELOW HERE -----------------------------------------#
####################################################################




cognito = boto.connect_cognito_identity()
cognito_id = cognito.get_id(ACCOUNT_ID, IDENTITY_POOL_ID)
oidc = cognito.get_open_id_token(cognito_id['IdentityId'])

sts = boto.connect_sts()
assumedRoleObject = sts.assume_role_with_web_identity(ROLE_ARN, "XX", oidc['Token'])

client_dynamo = boto.dynamodb2.connect_to_region(
        'us-east-1',
        aws_access_key_id=assumedRoleObject.credentials.access_key,
        aws_secret_access_key=assumedRoleObject.credentials.secret_key,
        security_token=assumedRoleObject.credentials.session_token)

DB = dynamoMethods(DYNAMO_TABLE_NAME)

state = 0
input_cuid = None
input_name = None
input_password = None

def get_prompt(state_var):
    if state_var == 0:
        return "Choose an option.\n1. Add to DB\n2. Delete from DB\n3. ViewDB\n"
    elif state_var == 1:
        return "Enter CUID to add: "
    elif state_var == 2:
        return "Enter name to add: "
    elif state_var == 3:
        return "Enter password: "******"Enter CUID to delete: "
    else:
        return "Bad command..."

try:
    while True:
        prompt = get_prompt(state)
        ans = raw_input(prompt)

        if state == 0:
            if ans == "1":
                state = 1
            elif ans == "2":
                state = 4
            elif ans == "3":
                state = 0
                DB.dynamoViewAll()
            else:
                print "Unsupported command.\n"
        elif state == 1:
            state = 2
            input_cuid = ans
        elif state == 2:
            state = 3
            input_name = ans
        elif state == 3:
            state = 0
            input_password = ans
            DB.dynamoAdd(input_cuid, input_name, input_password)
        elif state == 4:
            state = 0
            input_cuid = ans
            DB.dynamoDelete(input_cuid)
        else:
            state = 0
            print "Something is wrong."
except KeyboardInterrupt:
    exit