def test_init_with_profile(session, botocore_session): AWS.initialize(profile=PROFILE) botocore_session.assert_called_with(profile=PROFILE) session.assert_called_with(botocore_session=botocore_session())
def test_init_with_profile_and_region(session, botocore_session): AWS.initialize(profile=PROFILE, region=REGION) botocore_session.assert_called_with(profile=PROFILE) session.assert_called_with(botocore_session=botocore_session(), region_name=REGION)
def test_init_without_parameters(session, botocore_session): AWS.initialize() session.assert_called_with(botocore_session=botocore_session())
def test_init_with_region(session, botocore_session): AWS.initialize(region=REGION) session.assert_called_with(botocore_session=botocore_session(), region_name=REGION)
def test_AWS_is_singleton(session): AWS.initialize() AWS.current_session() AWS.current_session() session.assert_called_once()
def test_init_with_profile(session): AWS.initialize(profile=PROFILE) session.assert_called_with(profile_name=PROFILE)
def test_init_with_region(session): AWS.initialize(region=REGION) session.assert_called_with(region_name=REGION)
def test_init_without_parameters(session): AWS.initialize() session.assert_called_with()
def main(cli_args): parser = argparse.ArgumentParser() parser.add_argument('--version', action='version', version='{}'.format(__version__)) subparsers = parser.add_subparsers(title='commands', help='Command to use', dest='command') subparsers.required = True # Template Command Arguments template_parser = subparsers.add_parser( 'template', description='Print the current template') template_parser.add_argument('-y', '--yaml', help="print output as yaml", action="store_true") template_parser.set_defaults(func=template) # Stacks Command Arguments stacks_parser = subparsers.add_parser('stacks', description='List all stacks') add_aws_arguments(stacks_parser) add_config_file_argument(stacks_parser) stacks_parser.set_defaults(func=stacks) # New Command Arguments new_parser = subparsers.add_parser( 'new', description='Create a change set for a new stack') add_aws_arguments(new_parser) add_stack_argument(new_parser) add_stack_parameters_argument(new_parser) add_stack_tags_argument(new_parser) add_capabilities_argument(new_parser) add_config_file_argument(new_parser) new_parser.set_defaults(func=new) # Change Command Arguments change_parser = subparsers.add_parser( 'change', description='Create a change set for an existing stack') add_aws_arguments(change_parser) add_stack_argument(change_parser) add_stack_parameters_argument(change_parser) add_stack_tags_argument(change_parser) add_capabilities_argument(change_parser) add_config_file_argument(change_parser) change_parser.set_defaults(func=change) # Deploy Command Arguments deploy_parser = subparsers.add_parser( 'deploy', description='Deploy the latest change set for a stack') add_aws_arguments(deploy_parser) add_stack_argument(deploy_parser) add_config_file_argument(deploy_parser) deploy_parser.set_defaults(func=deploy) # Describe Command Arguments describe_parser = subparsers.add_parser( 'describe', description='Describe the latest change-set of the stack') add_aws_arguments(describe_parser) add_stack_argument(describe_parser) add_config_file_argument(describe_parser) describe_parser.set_defaults(func=describe) # Diff Command Arguments diff_parser = subparsers.add_parser( 'diff', description='Print a diff between local and deployed stack') add_aws_arguments(diff_parser) add_stack_argument(diff_parser) add_config_file_argument(diff_parser) diff_parser.set_defaults(func=diff) # Resources Command Arguments resources_parser = subparsers.add_parser( 'resources', description='List all resources of a stack') add_aws_arguments(resources_parser) add_stack_argument(resources_parser) add_config_file_argument(resources_parser) resources_parser.set_defaults(func=resources) # Remove Command Arguments remove_parser = subparsers.add_parser( 'remove', description='Remove the configured stack') add_aws_arguments(remove_parser) add_stack_argument(remove_parser) add_config_file_argument(remove_parser) remove_parser.set_defaults(func=remove) # Argument Parsing args = parser.parse_args(cli_args) args_dict = vars(args) if args_dict.get('config_file'): load_config_file(args, args.config_file) try: # Initialise the AWS Profile and Region AWS.initialize(args_dict.get('region'), args_dict.get('profile')) # Execute Function if args_dict.get('func'): args.func(args) else: parser.print_usage() except (ProfileNotFound, NoCredentialsError, NoRegionError, EndpointConnectionError) as e: logger.info( 'Please make sure your credentials, regions and profiles are properly set:' ) logger.info(e) sys.exit(1) except ClientError as e: if e.response['Error']['Code'] == 'ValidationError': logger.info(e.response['Error']['Message']) sys.exit(1) else: logger.info(e) sys.exit(2)