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


Python awsclient.TypedAWSClient类代码示例

本文整理汇总了Python中chalice.awsclient.TypedAWSClient的典型用法代码示例。如果您正苦于以下问题:Python TypedAWSClient类的具体用法?Python TypedAWSClient怎么用?Python TypedAWSClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_create_role_raises_error_on_failure

 def test_create_role_raises_error_on_failure(self, stubbed_session):
     arn = 'good_arn' * 3
     role_id = 'abcd' * 4
     today = datetime.datetime.today()
     stubbed_session.stub('iam').create_role(
         RoleName='role_name',
         AssumeRolePolicyDocument=json.dumps({'trust': 'policy'})
     ).returns({'Role': {
         'RoleName': 'No', 'Arn': arn, 'Path': '/',
         'RoleId': role_id, 'CreateDate': today}}
     )
     stubbed_session.stub('iam').put_role_policy(
         RoleName='role_name',
         PolicyName='role_name',
         PolicyDocument={'policy': 'document'}
     ).raises_error(
         error_code='MalformedPolicyDocumentException',
         message='MalformedPolicyDocument'
     )
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     with pytest.raises(botocore.exceptions.ClientError):
         awsclient.create_role(
             'role_name', {'trust': 'policy'}, {'policy': 'document'})
     stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:25,代码来源:test_awsclient.py

示例2: test_create_function_is_retried_and_succeeds

 def test_create_function_is_retried_and_succeeds(self, stubbed_session):
     kwargs = {
         'FunctionName': 'name',
         'Runtime': 'python2.7',
         'Code': {'ZipFile': b'foo'},
         'Handler': 'app.app',
         'Role': 'myarn',
     }
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
         error_code='InvalidParameterValueException',
         message=('The role defined for the function cannot '
                  'be assumed by Lambda.'))
     stubbed_session.stub('lambda').create_function(
         **kwargs).raises_error(
         error_code='InvalidParameterValueException',
         message=('The role defined for the function cannot '
                  'be assumed by Lambda.'))
     stubbed_session.stub('lambda').create_function(
         **kwargs).returns({'FunctionArn': 'arn:12345:name'})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
     assert awsclient.create_function(
         'name', 'myarn', b'foo',
         'python2.7', 'app.app') == 'arn:12345:name'
     stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:26,代码来源:test_awsclient.py

示例3: test_lambda_delete_function

 def test_lambda_delete_function(self, stubbed_session):
     stubbed_session.stub('lambda')\
                    .delete_function(FunctionName='name').returns({})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.delete_function('name') is None
     stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:7,代码来源:test_awsclient.py

示例4: test_can_iterate_logs

def test_can_iterate_logs(stubbed_session):
    stubbed_session.stub('logs').filter_log_events(
        logGroupName='loggroup', interleaved=True).returns({
            "events": [{
                "logStreamName": "logStreamName",
                "timestamp": 1501278366000,
                "message": "message",
                "ingestionTime": 1501278366000,
                "eventId": "eventId"
            }],
        })

    stubbed_session.activate_stubs()

    awsclient = TypedAWSClient(stubbed_session)
    logs = list(awsclient.iter_log_events('loggroup'))
    timestamp = datetime.datetime.fromtimestamp(1501278366)
    assert logs == [
        {'logStreamName': 'logStreamName',
         # We should have converted the ints to timestamps.
         'timestamp': timestamp,
         'message': 'message',
         'ingestionTime': timestamp,
         'eventId': 'eventId'}
    ]

    stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:27,代码来源:test_awsclient.py

示例5: test_update_function_is_retried_and_succeeds

    def test_update_function_is_retried_and_succeeds(self, stubbed_session):
        stubbed_session.stub('lambda').update_function_code(
            FunctionName='name', ZipFile=b'foo').returns(
                {'FunctionArn': 'arn'})

        update_config_kwargs = {
            'FunctionName': 'name',
            'Role': 'role-arn'
        }
        # This should fail two times with retryable exceptions and
        # then succeed to update the lambda function.
        stubbed_session.stub('lambda').update_function_configuration(
            **update_config_kwargs).raises_error(
                error_code='InvalidParameterValueException',
                message=('The role defined for the function cannot '
                         'be assumed by Lambda.'))
        stubbed_session.stub('lambda').update_function_configuration(
            **update_config_kwargs).raises_error(
            error_code='InvalidParameterValueException',
            message=('The role defined for the function cannot '
                     'be assumed by Lambda.'))
        stubbed_session.stub('lambda').update_function_configuration(
            **update_config_kwargs).returns({})
        stubbed_session.activate_stubs()
        awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
        awsclient.update_function('name', b'foo', role_arn='role-arn')
        stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:27,代码来源:test_awsclient.py

示例6: test_skip_if_permission_already_granted

def test_skip_if_permission_already_granted(stubbed_session):
    lambda_client = stubbed_session.stub('lambda')
    policy = {
        'Id': 'default',
        'Statement': [
            {'Action': 'lambda:InvokeFunction',
                'Condition': {
                    'ArnLike': {
                        'AWS:SourceArn': 'rule-arn',
                    }
                },
                'Effect': 'Allow',
                'Principal': {'Service': 'events.amazonaws.com'},
                'Resource': 'resource-arn',
                'Sid': 'statement-id'},
        ],
        'Version': '2012-10-17'
    }
    lambda_client.get_policy(
        FunctionName='function-arn').returns({'Policy': json.dumps(policy)})

    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.add_permission_for_scheduled_event(
        'rule-arn', 'function-arn')
    stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:26,代码来源:test_awsclient.py

示例7: test_update_function_code

def test_update_function_code(stubbed_session):
    stubbed_session.stub('lambda').update_function_code(
        FunctionName='name', ZipFile=b'foo').returns({})
    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.update_function_code('name', b'foo')
    stubbed_session.verify_stubs()
开发者ID:shunsuke-aikawa,项目名称:chalice,代码行数:7,代码来源:test_awsclient.py

示例8: test_create_rest_api

def test_create_rest_api(stubbed_session):
    stubbed_session.stub('apigateway').create_rest_api(
        name='name').returns({'id': 'rest_api_id'})
    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    assert awsclient.create_rest_api('name') == 'rest_api_id'
    stubbed_session.verify_stubs()
开发者ID:shunsuke-aikawa,项目名称:chalice,代码行数:7,代码来源:test_awsclient.py

示例9: test_delete_resource_for_api

def test_delete_resource_for_api(stubbed_session):
    stubbed_session.stub('apigateway').delete_resource(
        restApiId='api_id', resourceId='resource_id').returns({})
    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.delete_resource_for_api('api_id', 'resource_id')
    stubbed_session.verify_stubs()
开发者ID:shunsuke-aikawa,项目名称:chalice,代码行数:7,代码来源:test_awsclient.py

示例10: test_rest_api_delete

 def test_rest_api_delete(self, stubbed_session):
     stubbed_session.stub('apigateway')\
                    .delete_rest_api(restApiId='name').returns({})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     assert awsclient.delete_rest_api('name') is None
     stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:7,代码来源:test_awsclient.py

示例11: generate_sdk

def generate_sdk(ctx, sdk_type, outdir):
    # type: (click.Context, str, str) -> None
    config = create_config_obj(ctx)
    session = create_botocore_session(profile=config.profile,
                                      debug=ctx.obj['debug'])
    client = TypedAWSClient(session)
    rest_api_id = client.get_rest_api_id(config.app_name)
    stage_name = config.stage
    if rest_api_id is None:
        click.echo("Could not find API ID, has this application "
                   "been deployed?")
        raise click.Abort()
    zip_stream = client.get_sdk(rest_api_id, stage=stage_name,
                                sdk_type=sdk_type)
    tmpdir = tempfile.mkdtemp()
    with open(os.path.join(tmpdir, 'sdk.zip'), 'wb') as f:
        f.write(zip_stream.read())
    tmp_extract = os.path.join(tmpdir, 'extracted')
    with zipfile.ZipFile(os.path.join(tmpdir, 'sdk.zip')) as z:
        z.extractall(tmp_extract)
    # The extract zip dir will have a single directory:
    #  ['apiGateway-js-sdk']
    dirnames = os.listdir(tmp_extract)
    if len(dirnames) == 1:
        full_dirname = os.path.join(tmp_extract, dirnames[0])
        if os.path.isdir(full_dirname):
            final_dirname = '%s-js-sdk' % config.app_name
            full_renamed_name = os.path.join(tmp_extract, final_dirname)
            os.rename(full_dirname, full_renamed_name)
            shutil.move(full_renamed_name, outdir)
            return
    click.echo("The downloaded SDK had an unexpected directory structure: %s"
               % (', '.join(dirnames)))
    raise click.Abort()
开发者ID:shunsuke-aikawa,项目名称:chalice,代码行数:34,代码来源:__init__.py

示例12: test_can_delete_role_policy

 def test_can_delete_role_policy(self, stubbed_session):
     stubbed_session.stub('iam').delete_role_policy(
         RoleName='myrole', PolicyName='mypolicy'
     ).returns({})
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     awsclient.delete_role_policy('myrole', 'mypolicy')
     stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:8,代码来源:test_awsclient.py

示例13: test_can_add_permission_for_apigateway_not_needed

    def test_can_add_permission_for_apigateway_not_needed(self,
                                                          stubbed_session):
        source_arn = 'arn:aws:execute-api:us-west-2:123:rest-api-id/*'
        wrong_action = {
            'Action': 'lambda:NotInvoke',
            'Condition': {
                'ArnLike': {
                    'AWS:SourceArn': source_arn,
                }
            },
            'Effect': 'Allow',
            'Principal': {'Service': 'apigateway.amazonaws.com'},
            'Resource': 'arn:aws:lambda:us-west-2:account_id:function:name',
            'Sid': 'e4755709-067e-4254-b6ec-e7f9639e6f7b',
        }
        wrong_service_name = {
            'Action': 'lambda:Invoke',
            'Condition': {
                'ArnLike': {
                    'AWS:SourceArn': source_arn,
                }
            },
            'Effect': 'Allow',
            'Principal': {'Service': 'NOT-apigateway.amazonaws.com'},
            'Resource': 'arn:aws:lambda:us-west-2:account_id:function:name',
            'Sid': 'e4755709-067e-4254-b6ec-e7f9639e6f7b',
        }
        correct_statement = {
            'Action': 'lambda:InvokeFunction',
            'Condition': {
                'ArnLike': {
                    'AWS:SourceArn': source_arn,
                }
            },
            'Effect': 'Allow',
            'Principal': {'Service': 'apigateway.amazonaws.com'},
            'Resource': 'arn:aws:lambda:us-west-2:account_id:function:name',
            'Sid': 'e4755709-067e-4254-b6ec-e7f9639e6f7b',
        }
        policy = {
            'Id': 'default',
            'Statement': [
                wrong_action,
                wrong_service_name,
                correct_statement,
            ],
            'Version': '2012-10-17'
        }
        stubbed_session.stub('lambda').get_policy(
            FunctionName='name').returns({'Policy': json.dumps(policy)})

        # Because the policy above indicates that API gateway already has the
        # necessary permissions, we should not call add_permission.
        stubbed_session.activate_stubs()
        client = TypedAWSClient(stubbed_session)
        client.add_permission_for_apigateway_if_needed(
            'name', 'us-west-2', '123', 'rest-api-id', 'random-id')
        stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:58,代码来源:test_awsclient.py

示例14: test_unexpected_error_is_propagated

 def test_unexpected_error_is_propagated(self, stubbed_session):
     stubbed_session.stub('iam').get_role(RoleName='Yes').raises_error(
         error_code='InternalError',
         message='Foo')
     stubbed_session.activate_stubs()
     awsclient = TypedAWSClient(stubbed_session)
     with pytest.raises(botocore.exceptions.ClientError):
         awsclient.get_role_arn_for_name(name='Yes')
     stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:9,代码来源:test_awsclient.py

示例15: test_deploy_rest_api

def test_deploy_rest_api(stubbed_session):
    stub_client = stubbed_session.stub('apigateway')
    stub_client.create_deployment(
        restApiId='api_id', stageName='stage').returns({})

    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.deploy_rest_api('api_id', 'stage')
    stubbed_session.verify_stubs()
开发者ID:jamesls,项目名称:chalice,代码行数:9,代码来源:test_awsclient.py


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