def do_cli(
    template_file,
    stack_name,
    s3_bucket,
    force_upload,
    s3_prefix,
    kms_key_id,
    parameter_overrides,
    capabilities,
    no_execute_changeset,
    role_arn,
    notification_arns,
    fail_on_empty_changeset,
    use_json,
    tags,
    metadata,
    guided,
    confirm_changeset,
    region,
    profile,
):
    from samcli.commands.package.package_context import PackageContext
    from samcli.commands.deploy.deploy_context import DeployContext
    from samcli.commands.deploy.guided_context import GuidedContext

    if guided:
        # Allow for a guided deploy to prompt and save those details.
        guided_context = GuidedContext(
            template_file=template_file,
            stack_name=stack_name,
            s3_bucket=s3_bucket,
            s3_prefix=s3_prefix,
            region=region,
            profile=profile,
            confirm_changeset=confirm_changeset,
            capabilities=capabilities,
            parameter_overrides=parameter_overrides,
            config_section=CONFIG_SECTION,
        )
        guided_context.run()

    print_deploy_args(
        stack_name=guided_context.guided_stack_name if guided else stack_name,
        s3_bucket=guided_context.guided_s3_bucket if guided else s3_bucket,
        region=guided_context.guided_region if guided else region,
        capabilities=guided_context.guided_capabilities
        if guided else capabilities,
        parameter_overrides=guided_context.guided_parameter_overrides
        if guided else parameter_overrides,
        confirm_changeset=guided_context.confirm_changeset
        if guided else confirm_changeset,
    )

    with osutils.tempfile_platform_independent() as output_template_file:

        with PackageContext(
                template_file=template_file,
                s3_bucket=guided_context.guided_s3_bucket
                if guided else s3_bucket,
                s3_prefix=guided_context.guided_s3_prefix
                if guided else s3_prefix,
                output_template_file=output_template_file.name,
                kms_key_id=kms_key_id,
                use_json=use_json,
                force_upload=force_upload,
                metadata=metadata,
                on_deploy=True,
                region=guided_context.guided_region if guided else region,
                profile=profile,
        ) as package_context:
            package_context.run()

        with DeployContext(
                template_file=output_template_file.name,
                stack_name=guided_context.guided_stack_name
                if guided else stack_name,
                s3_bucket=guided_context.guided_s3_bucket
                if guided else s3_bucket,
                force_upload=force_upload,
                s3_prefix=guided_context.guided_s3_prefix
                if guided else s3_prefix,
                kms_key_id=kms_key_id,
                parameter_overrides=sanitize_parameter_overrides(
                    guided_context.guided_parameter_overrides)
                if guided else parameter_overrides,
                capabilities=guided_context.guided_capabilities
                if guided else capabilities,
                no_execute_changeset=no_execute_changeset,
                role_arn=role_arn,
                notification_arns=notification_arns,
                fail_on_empty_changeset=fail_on_empty_changeset,
                tags=tags,
                region=guided_context.guided_region if guided else region,
                profile=profile,
                confirm_changeset=guided_context.confirm_changeset
                if guided else confirm_changeset,
        ) as deploy_context:
            deploy_context.run()
Beispiel #2
0
def do_cli(
    template_file,
    stack_name,
    s3_bucket,
    force_upload,
    no_progressbar,
    s3_prefix,
    kms_key_id,
    parameter_overrides,
    capabilities,
    no_execute_changeset,
    role_arn,
    notification_arns,
    fail_on_empty_changeset,
    use_json,
    tags,
    metadata,
    guided,
    confirm_changeset,
    region,
    profile,
    signing_profiles,
    resolve_s3,
    config_file,
    config_env,
):
    from samcli.commands.package.package_context import PackageContext
    from samcli.commands.deploy.deploy_context import DeployContext
    from samcli.commands.deploy.guided_context import GuidedContext
    from samcli.commands.deploy.exceptions import DeployResolveS3AndS3SetError

    if guided:
        # Allow for a guided deploy to prompt and save those details.
        guided_context = GuidedContext(
            template_file=template_file,
            stack_name=stack_name,
            s3_bucket=s3_bucket,
            s3_prefix=s3_prefix,
            region=region,
            profile=profile,
            confirm_changeset=confirm_changeset,
            capabilities=capabilities,
            signing_profiles=signing_profiles,
            parameter_overrides=parameter_overrides,
            config_section=CONFIG_SECTION,
            config_env=config_env,
            config_file=config_file,
        )
        guided_context.run()
    elif resolve_s3 and bool(s3_bucket):
        raise DeployResolveS3AndS3SetError()
    elif resolve_s3:
        s3_bucket = manage_stack(profile=profile, region=region)
        click.echo(f"\n\t\tManaged S3 bucket: {s3_bucket}")
        click.echo(
            "\t\tA different default S3 bucket can be set in samconfig.toml")
        click.echo("\t\tOr by specifying --s3-bucket explicitly.")

    with osutils.tempfile_platform_independent() as output_template_file:

        with PackageContext(
                template_file=template_file,
                s3_bucket=guided_context.guided_s3_bucket
                if guided else s3_bucket,
                s3_prefix=guided_context.guided_s3_prefix
                if guided else s3_prefix,
                output_template_file=output_template_file.name,
                kms_key_id=kms_key_id,
                use_json=use_json,
                force_upload=force_upload,
                no_progressbar=no_progressbar,
                metadata=metadata,
                on_deploy=True,
                region=guided_context.guided_region if guided else region,
                profile=profile,
                signing_profiles=guided_context.signing_profiles
                if guided else signing_profiles,
        ) as package_context:
            package_context.run()

        with DeployContext(
                template_file=output_template_file.name,
                stack_name=guided_context.guided_stack_name
                if guided else stack_name,
                s3_bucket=guided_context.guided_s3_bucket
                if guided else s3_bucket,
                force_upload=force_upload,
                no_progressbar=no_progressbar,
                s3_prefix=guided_context.guided_s3_prefix
                if guided else s3_prefix,
                kms_key_id=kms_key_id,
                parameter_overrides=sanitize_parameter_overrides(
                    guided_context.guided_parameter_overrides)
                if guided else parameter_overrides,
                capabilities=guided_context.guided_capabilities
                if guided else capabilities,
                no_execute_changeset=no_execute_changeset,
                role_arn=role_arn,
                notification_arns=notification_arns,
                fail_on_empty_changeset=fail_on_empty_changeset,
                tags=tags,
                region=guided_context.guided_region if guided else region,
                profile=profile,
                confirm_changeset=guided_context.confirm_changeset
                if guided else confirm_changeset,
                signing_profiles=guided_context.signing_profiles
                if guided else signing_profiles,
        ) as deploy_context:
            deploy_context.run()