当前位置: 首页>>代码示例>>Python>>正文


Python session.Session方法代码示例

本文整理汇总了Python中boto3.session.Session方法的典型用法代码示例。如果您正苦于以下问题:Python session.Session方法的具体用法?Python session.Session怎么用?Python session.Session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto3.session的用法示例。


在下文中一共展示了session.Session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init_boto_client

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def init_boto_client(client_name, region, args):
    """
    Initiates boto's client object
    :param client_name: client name
    :param region: region name
    :param args: arguments
    :return: Client
    """
    if args.token_key_id and args.token_secret:
        boto_client = boto3.client(
            client_name,
            aws_access_key_id=args.token_key_id,
            aws_secret_access_key=args.token_secret,
            region_name=region
        )
    elif args.profile:
        session = boto3.session.Session(profile_name=args.profile)
        boto_client = session.client(client_name, region_name=region)
    else:
        boto_client = boto3.client(client_name, region_name=region)

    return boto_client 
开发者ID:epsagon,项目名称:clear-lambda-storage,代码行数:24,代码来源:clear_lambda_storage.py

示例2: setup_cloudwatch_logging

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def setup_cloudwatch_logging(logger):
    """Add Cloud Watch log handler if appropriate."""
    if not (Config.CW_AWS_ACCESS_KEY_ID and Config.CW_AWS_SECRET_ACCESS_KEY):
        logger.info("CloudWatch logging disabled due to missing access key")
        return

    try:
        session = Session(
            aws_access_key_id=Config.CW_AWS_ACCESS_KEY_ID,
            aws_secret_access_key=Config.CW_AWS_SECRET_ACCESS_KEY,
            region_name=Config.CW_AWS_REGION,
        )
        handler = watchtower.CloudWatchLogHandler(
            boto3_session=session, log_group=Config.CW_LOG_GROUP, stream_name=Config.NAMESPACE, create_log_group=False
        )
        logger.addHandler(handler)
    except ClientError as cerr:
        logger.error("CloudWatch logging setup failed: %s", cerr) 
开发者ID:project-koku,项目名称:koku,代码行数:20,代码来源:__init__.py

示例3: setup

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def setup(event):
    # Extract attributes passed in by CodePipeline
    job_id = event['CodePipeline.job']['id']
    job_data = event['CodePipeline.job']['data']
    artifact = job_data['inputArtifacts'][0]
    config = job_data['actionConfiguration']['configuration']
    credentials = job_data['artifactCredentials']
    from_bucket = artifact['location']['s3Location']['bucketName']
    from_key = artifact['location']['s3Location']['objectKey']
    from_revision = artifact['revision']
    #output_artifact = job_data['outputArtifacts'][0]
    #to_bucket = output_artifact['location']['s3Location']['bucketName']
    #to_key = output_artifact['location']['s3Location']['objectKey']

    # Temporary credentials to access CodePipeline artifact in S3
    key_id = credentials['accessKeyId']
    key_secret = credentials['secretAccessKey']
    session_token = credentials['sessionToken']
    session = Session(aws_access_key_id=key_id,
                      aws_secret_access_key=key_secret,
                      aws_session_token=session_token)
    s3 = session.client('s3',
                        config=botocore.client.Config(signature_version='s3v4'))

    return (job_id, s3, from_bucket, from_key, from_revision) 
开发者ID:alestic,项目名称:aws-git-backed-static-website,代码行数:27,代码来源:aws-git-backed-static-website-lambda.py

示例4: read_job_info

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def read_job_info(event):

    tmp_file = tempfile.NamedTemporaryFile()

    objectKey = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['objectKey']
    print("[INFO]Object Key:", objectKey)

    bucketname = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['bucketName']
    print("[INFO]Bucket Name:", bucketname)

    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                  aws_secret_access_key=artifactCredentials['secretAccessKey'],
                  aws_session_token=artifactCredentials['sessionToken'])
   
 
    s3 = session.resource('s3')

    obj = s3.Object(bucketname,objectKey)
      
    item = json.loads(obj.get()['Body'].read().decode('utf-8'))
      
    return item 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:26,代码来源:MLOps-BIA-GetStatus.py

示例5: write_job_info_s3

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def write_job_info_s3(event, writeData):

    objectKey = event['CodePipeline.job']['data']['outputArtifacts'][0]['location']['s3Location']['objectKey']

    bucketname = event['CodePipeline.job']['data']['outputArtifacts'][0]['location']['s3Location']['bucketName']

    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']

    artifactName = event['CodePipeline.job']['data']['outputArtifacts'][0]['name']
    json_data = json.dumps(writeData, indent=4, sort_keys=True, default=str)

    print(json_data)

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                  aws_secret_access_key=artifactCredentials['secretAccessKey'],
                  aws_session_token=artifactCredentials['sessionToken'])
   

    s3 = session.resource("s3")
    #object = s3.Object(bucketname, objectKey + '/event.json')
    object = s3.Object(bucketname, objectKey)
    print(object)
    object.put(Body=json_data, ServerSideEncryption='aws:kms', SSEKMSKeyId=SSEKMSKeyId)
    print('[INFO]event written to s3') 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:26,代码来源:MLOps-BIA-GetStatus.py

示例6: write_job_info_s3

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def write_job_info_s3(event):
    print(event)

    objectKey = event['CodePipeline.job']['data']['outputArtifacts'][0]['location']['s3Location']['objectKey']
    bucketname = event['CodePipeline.job']['data']['outputArtifacts'][0]['location']['s3Location']['bucketName']
    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']
    artifactName = event['CodePipeline.job']['data']['outputArtifacts'][0]['name']
    
    # S3 Managed Key for Encryption
    S3SSEKey = os.environ['SSEKMSKeyIdIn']

    json_data = json.dumps(event)
    print(json_data)

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                  aws_secret_access_key=artifactCredentials['secretAccessKey'],
                  aws_session_token=artifactCredentials['sessionToken'])
   

    s3 = session.resource("s3")
    object = s3.Object(bucketname, objectKey)
    print(object)
    object.put(Body=json_data, ServerSideEncryption='aws:kms', SSEKMSKeyId=S3SSEKey)
    
    print('[SUCCESS]Job Information Written to S3') 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:27,代码来源:MLOps-BIA-TrainModel.py

示例7: read_job_info

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def read_job_info(event):

    print("[DEBUG]EVENT IN:", event)
    bucketname = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['bucketName']
    print("[INFO]Previous Job Info Bucket:", bucketname)
    
    objectKey = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['objectKey']
    print("[INFO]Previous Job Info Object:", objectKey)

    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                  aws_secret_access_key=artifactCredentials['secretAccessKey'],
                  aws_session_token=artifactCredentials['sessionToken'])
   
 
    s3 = session.resource('s3')

    obj = s3.Object(bucketname,objectKey)
  
    item = json.loads(obj.get()['Body'].read().decode('utf-8'))
    
    print("[INFO]Previous CodePipeline Job Info Sucessfully Read:", item)
    return item 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:26,代码来源:MLOps-BIA-EvaluateModel.py

示例8: read_job_info

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def read_job_info(event):

    objectKey = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['objectKey']
    bucketname = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['bucketName']

    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                  aws_secret_access_key=artifactCredentials['secretAccessKey'],
                  aws_session_token=artifactCredentials['sessionToken'])
   
 
    s3 = session.resource('s3')

    obj = s3.Object(bucketname,objectKey)
    
    item = json.loads(obj.get()['Body'].read().decode('utf-8'))
    
    print("[INFO]Previous CodePipeline Job Info Sucessfully Read:", item)
    return item 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:22,代码来源:MLOps-BYO-EvaluateModel.py

示例9: read_job_info

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def read_job_info(event):
    tmp_file = tempfile.NamedTemporaryFile()

    objectKey = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['objectKey']
    print("[INFO]Object Key:", objectKey)

    bucketname = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['bucketName']
    print("[INFO]Bucket Name:", bucketname)

    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                      aws_secret_access_key=artifactCredentials['secretAccessKey'],
                      aws_session_token=artifactCredentials['sessionToken'])

    s3 = session.resource('s3')

    obj = s3.Object(bucketname, objectKey)

    item = json.loads(obj.get()['Body'].read().decode('utf-8'))

    return item 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:24,代码来源:MLOps-BIA-GetStatus.py

示例10: write_job_info_s3

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def write_job_info_s3(event, writeData):
    objectKey = event['CodePipeline.job']['data']['outputArtifacts'][0]['location']['s3Location']['objectKey']

    bucketname = event['CodePipeline.job']['data']['outputArtifacts'][0]['location']['s3Location']['bucketName']

    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']

    artifactName = event['CodePipeline.job']['data']['outputArtifacts'][0]['name']
    json_data = json.dumps(writeData, indent=4, sort_keys=True, default=str)

    print(json_data)

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                      aws_secret_access_key=artifactCredentials['secretAccessKey'],
                      aws_session_token=artifactCredentials['sessionToken'])

    s3 = session.resource("s3")
    # object = s3.Object(bucketname, objectKey + '/event.json')
    object = s3.Object(bucketname, objectKey)
    print(object)
    object.put(Body=json_data, ServerSideEncryption='aws:kms', SSEKMSKeyId=SSEKMSKeyId)
    print('[INFO]event written to s3') 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:24,代码来源:MLOps-BIA-GetStatus.py

示例11: read_job_info

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def read_job_info(event):
    tmp_file = tempfile.NamedTemporaryFile()

    objectKey = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['objectKey']

    print("[INFO]Object:", objectKey)

    bucketname = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['bucketName']
    print("[INFO]Bucket:", bucketname)

    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                      aws_secret_access_key=artifactCredentials['secretAccessKey'],
                      aws_session_token=artifactCredentials['sessionToken'])

    s3 = session.resource('s3')

    obj = s3.Object(bucketname, objectKey)

    item = json.loads(obj.get()['Body'].read().decode('utf-8'))

    print("Item:", item)

    return item 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:27,代码来源:MLOps-BIA-DeployModel.py

示例12: write_job_info_s3

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def write_job_info_s3(event):
    KMSKeyIdSSEIn = os.environ['SSEKMSKeyIdIn']

    objectKey = event['CodePipeline.job']['data']['outputArtifacts'][0]['location']['s3Location']['objectKey']
    bucketname = event['CodePipeline.job']['data']['outputArtifacts'][0]['location']['s3Location']['bucketName']

    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']
    artifactName = event['CodePipeline.job']['data']['outputArtifacts'][0]['name']

    json_data = json.dumps(event)

    print(json_data)

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                      aws_secret_access_key=artifactCredentials['secretAccessKey'],
                      aws_session_token=artifactCredentials['sessionToken'])

    s3 = session.resource("s3")
    object = s3.Object(bucketname, objectKey + '/event.json')
    object = s3.Object(bucketname, objectKey)
    print(object)
    object.put(Body=json_data, ServerSideEncryption='aws:kms', SSEKMSKeyId=KMSKeyIdSSEIn) 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:24,代码来源:MLOps-BIA-EvaluateModel.py

示例13: read_job_info

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def read_job_info(event):
    print("[DEBUG]EVENT IN:", event)
    bucketname = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['bucketName']
    print("[INFO]Previous Job Info Bucket:", bucketname)

    objectKey = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['objectKey']
    print("[INFO]Previous Job Info Object:", objectKey)

    artifactCredentials = event['CodePipeline.job']['data']['artifactCredentials']

    session = Session(aws_access_key_id=artifactCredentials['accessKeyId'],
                      aws_secret_access_key=artifactCredentials['secretAccessKey'],
                      aws_session_token=artifactCredentials['sessionToken'])

    s3 = session.resource('s3')

    obj = s3.Object(bucketname, objectKey)

    item = json.loads(obj.get()['Body'].read().decode('utf-8'))

    print("[INFO]Previous CodePipeline Job Info Sucessfully Read:", item)
    return item 
开发者ID:aws-samples,项目名称:mlops-amazon-sagemaker-devops-with-ml,代码行数:24,代码来源:MLOps-BIA-EvaluateModel.py

示例14: create_boto_session

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def create_boto_session(taskproc_config, region):
    # first, try to load credentials
    credentials_file = taskproc_config.get("boto_credential_file")
    if credentials_file:
        with open(credentials_file) as f:
            credentials = json.loads(f.read())
    else:
        raise ValueError("Required aws credentials")

    # second, create the session for the given region
    return Session(
        region_name=region,
        aws_access_key_id=credentials["accessKeyId"],
        aws_secret_access_key=credentials["secretAccessKey"],
    )


# TODO: rename to registry? 
开发者ID:Yelp,项目名称:paasta,代码行数:20,代码来源:paasta_remote_run.py

示例15: get_token

# 需要导入模块: from boto3 import session [as 别名]
# 或者: from boto3.session import Session [as 别名]
def get_token(self) -> Optional[str]:
        session = Session()
        client = session.client(service_name="secretsmanager", region_name=self.region)
        try:
            get_secret_value_response = client.get_secret_value(SecretId=self.secret_name)
        except ClientError as e:
            if e.response["Error"]["Code"] == "ResourceNotFoundException":
                raise AwsSecretsManagerTokenRetrievalException(f"The requested secret {self.secret_name} was not found")
            elif e.response["Error"]["Code"] == "InvalidRequestException":
                raise AwsSecretsManagerTokenRetrievalException("The request was invalid")
            elif e.response["Error"]["Code"] == "InvalidParameterException":
                raise AwsSecretsManagerTokenRetrievalException("The request had invalid params")
        else:
            if "SecretString" in get_secret_value_response:
                secret = json.loads(get_secret_value_response["SecretString"])
                try:
                    return secret[self.secret_key]
                except KeyError:
                    raise AwsSecretsManagerTokenRetrievalException(f"Invalid secret_key parameter: {self.secret_key}")
            else:
                raise AwsSecretsManagerTokenRetrievalException(
                    "Invalid secret format. It should be a SecretString, instead of binary."
                ) 
开发者ID:mtakaki,项目名称:cachet-url-monitor,代码行数:25,代码来源:token_provider.py


注:本文中的boto3.session.Session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。