def __init__(self, name, version): self.function_name = name self.function_version = version self.invoked_function_arn = ( "arn:aws:lambda:us-east-1:123456789012:function:{name}:{version}".format(name=name, version=version)) self.memory_limit_in_mb = float('inf') self.log_group_name = 'test-group' self.log_stream_name = 'test-stream' self.client_context = None self.aws_request_id = '-'.join(map( lambda n: ''.join(map(lambda _: random.choice('0123456789abcdef'), range(0, n))), [8, 4, 4, 4, 12] )) # # Get an identity ID self.identity = lambda: None self.identity.cognito_identity_pool_id = env.IDENTITY_POOL self.identity.cognito_identity_id = common.get_identity() if (self.identity.cognito_identity_id is False): print "Get new Identity from Cognito" # Get Cognito identity res = boto3.client('cognito-identity').get_id( AccountId=env.AWS_ACCOUNT_ID, IdentityPoolId=env.IDENTITY_POOL ) self.identity.cognito_identity_id = res['IdentityId'] # Cache identity common.put_identity(self.identity.cognito_identity_id) print "\nYOUR Cognito IdentityId is: " print "--------------------------\n"+self.identity.cognito_identity_id print "\nResults:\n--------"
def __init__(self, verbose=0, noauth=0): if verbose == 1: httplib.HTTPConnection.debuglevel = 1 logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True self.IdentityId = common.get_identity() # We don't have a cached Identity. Get a new one if (noauth == 0 and self.IdentityId is False): print "Get new Identity from Cognito" # Get Cognito identity res = boto3.client('cognito-identity').get_id( AccountId=env.AWS_ACCOUNT_ID, IdentityPoolId=env.IDENTITY_POOL ) self.IdentityId = res['IdentityId'] # Cache identity common.put_identity(self.IdentityId) print "\nYOUR Cognito IdentityId is: " print "--------------------------\n"+self.IdentityId print "" # Get OpenId token to use for getting credentials res = boto3.client('cognito-identity').get_open_id_token( IdentityId=self.IdentityId ) # Get temporary credentials res = boto3.client('cognito-identity').get_credentials_for_identity( IdentityId=self.IdentityId ) self.access_key = res['Credentials']['AccessKeyId'] self.secret_key = res['Credentials']['SecretKey'] self.session_token = res['Credentials']['SessionToken']
def __init__(self, verbose=0, noauth=0): if verbose == 1: httplib.HTTPConnection.debuglevel = 1 logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True self.IdentityId = common.get_identity() # We don't have a cached Identity. Get a new one if noauth == 0 and self.IdentityId is False: print "Get new Identity from Cognito" # Get Cognito identity res = boto3.client("cognito-identity").get_id( AccountId=env.AWS_ACCOUNT_ID, IdentityPoolId=env.IDENTITY_POOL ) self.IdentityId = res["IdentityId"] # Cache identity common.put_identity(self.IdentityId) print "\nYOUR Cognito IdentityId is: " print "--------------------------\n" + self.IdentityId print "" # Get OpenId token to use for getting credentials res = boto3.client("cognito-identity").get_open_id_token(IdentityId=self.IdentityId) # Get temporary credentials res = boto3.client("cognito-identity").get_credentials_for_identity(IdentityId=self.IdentityId) self.access_key = res["Credentials"]["AccessKeyId"] self.secret_key = res["Credentials"]["SecretKey"] self.session_token = res["Credentials"]["SessionToken"]