Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions samcli/commands/deploy/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
is_flag=True,
help="Prompt to confirm if the computed changeset is to be deployed by SAM CLI.",
)
@click.option(
"--import-existing-resources/--no-import-existing-resources",
default=False,
required=False,
is_flag=True,
help="Requests CloudFormation to import any existing referenced by the template when creating the changeset.",
)
@click.option(
"--disable-rollback/--no-disable-rollback",
default=False,
Expand Down Expand Up @@ -198,6 +205,7 @@ def cli(
config_file,
config_env,
disable_rollback,
import_existing_resources,
on_failure,
max_wait_duration,
):
Expand Down Expand Up @@ -234,6 +242,7 @@ def cli(
config_env,
resolve_image_repos,
disable_rollback,
import_existing_resources,
on_failure,
max_wait_duration,
) # pragma: no cover
Expand Down Expand Up @@ -268,6 +277,7 @@ def do_cli(
config_env,
resolve_image_repos,
disable_rollback,
import_existing_resources,
on_failure,
max_wait_duration,
):
Expand Down Expand Up @@ -373,6 +383,7 @@ def do_cli(
signing_profiles=guided_context.signing_profiles if guided else signing_profiles,
use_changeset=True,
disable_rollback=guided_context.disable_rollback if guided else disable_rollback,
import_existing_resources=import_existing_resources,
poll_delay=poll_delay,
on_failure=on_failure,
max_wait_duration=max_wait_duration,
Expand Down
1 change: 1 addition & 0 deletions samcli/commands/deploy/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"fail_on_empty_changeset",
"confirm_changeset",
"disable_rollback",
"import_existing_resources",
"on_failure",
"force_upload",
"max_wait_duration",
Expand Down
8 changes: 8 additions & 0 deletions samcli/commands/deploy/deploy_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(
signing_profiles,
use_changeset,
disable_rollback,
import_existing_resources,
poll_delay,
on_failure,
max_wait_duration,
Expand Down Expand Up @@ -104,6 +105,7 @@ def __init__(
self.signing_profiles = signing_profiles
self.use_changeset = use_changeset
self.disable_rollback = disable_rollback
self.import_existing_resources = import_existing_resources
self.poll_delay = poll_delay
self.on_failure = FailureMode(on_failure) if on_failure else FailureMode.ROLLBACK
self._max_template_size = 51200
Expand Down Expand Up @@ -164,6 +166,7 @@ def run(self):
self.signing_profiles,
self.use_changeset,
self.disable_rollback,
self.import_existing_resources,
)
return self.deploy(
self.stack_name,
Expand All @@ -180,6 +183,7 @@ def run(self):
self.confirm_changeset,
self.use_changeset,
self.disable_rollback,
self.import_existing_resources,
)

def deploy(
Expand All @@ -198,6 +202,7 @@ def deploy(
confirm_changeset: bool = False,
use_changeset: bool = True,
disable_rollback: bool = False,
import_existing_resources: bool = False,
):
"""
Deploy the stack to cloudformation.
Expand Down Expand Up @@ -234,6 +239,8 @@ def deploy(
Involve creation of changesets, false when using sam sync
disable_rollback : bool
Preserves the state of previously provisioned resources when an operation fails
import_existing_resources : bool
Changeset should attempt to import existing resources as supported by cloudformation
"""
stacks, _ = SamLocalStackProvider.get_stacks(
self.template_file,
Expand All @@ -257,6 +264,7 @@ def deploy(
notification_arns=notification_arns,
s3_uploader=s3_uploader,
tags=tags,
import_existing_resources=import_existing_resources,
)
click.echo(self.MSG_SHOWCASE_CHANGESET.format(changeset_id=result["Id"]))

Expand Down
3 changes: 3 additions & 0 deletions samcli/commands/deploy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def print_deploy_args(
signing_profiles,
use_changeset,
disable_rollback,
import_existing_resources,
):
"""
Print a table of the values that are used during a sam deploy.
Expand All @@ -33,6 +34,7 @@ def print_deploy_args(
Region : us-east-1
Confirm changeset : False
Disable rollback : False
Import Existing Resources : False
Deployment s3 bucket : aws-sam-cli-managed-default-samclisourcebucket-abcdef
Capabilities : ["CAPABILITY_IAM"]
Parameter overrides : {'MyParamater': '***', 'Parameter2': 'dd'}
Expand Down Expand Up @@ -70,6 +72,7 @@ def print_deploy_args(
if use_changeset:
click.echo(f"\tConfirm changeset : {confirm_changeset}")
click.echo(f"\tDisable rollback : {disable_rollback}")
click.echo(f"\tImport Existing Resources : {import_existing_resources}")
if image_repository:
msg = "Deployment image repository : "
# NOTE(sriram-mv): tab length is 8 spaces.
Expand Down
1 change: 1 addition & 0 deletions samcli/commands/sync/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def do_cli(
force_upload=True,
signing_profiles=None,
disable_rollback=False,
import_existing_resources=False,
poll_delay=poll_delay,
on_failure=None,
max_wait_duration=60,
Expand Down
38 changes: 33 additions & 5 deletions samcli/lib/deploy/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,16 @@ def has_stack(self, stack_name):
raise e

def create_changeset(
self, stack_name, cfn_template, parameter_values, capabilities, role_arn, notification_arns, s3_uploader, tags
self,
stack_name,
cfn_template,
parameter_values,
capabilities,
role_arn,
notification_arns,
s3_uploader,
tags,
import_existing_resources,
):
"""
Call Cloudformation to create a changeset and wait for it to complete
Expand All @@ -154,6 +163,7 @@ def create_changeset(
:param notification_arns: Arns for sending notifications
:param s3_uploader: S3Uploader object to upload files to S3 buckets
:param tags: Array of tags passed to CloudFormation
:param import_existing_resources: Argument passed to CloudFormation
:return:
"""
if not self.has_stack(stack_name):
Expand Down Expand Up @@ -183,6 +193,7 @@ def create_changeset(
"Parameters": parameter_values,
"Description": "Created by SAM CLI at {0} UTC".format(datetime.utcnow().isoformat()),
"Tags": tags,
"ImportExistingResources": import_existing_resources,
}

kwargs = self._process_kwargs(kwargs, s3_uploader, capabilities, role_arn, notification_arns)
Expand Down Expand Up @@ -245,8 +256,8 @@ def describe_changeset(self, change_set_id, stack_name, **kwargs):
"""
paginator = self._client.get_paginator("describe_change_set")
response_iterator = paginator.paginate(ChangeSetName=change_set_id, StackName=stack_name)
changes = {"Add": [], "Modify": [], "Remove": []}
changes_showcase = {"Add": "+ Add", "Modify": "* Modify", "Remove": "- Delete"}
changes = {"Add": [], "Modify": [], "Remove": [], "Import": []}
changes_showcase = {"Add": "+ Add", "Modify": "* Modify", "Remove": "- Delete", "Import": "~ Import"}
changeset = False
for item in response_iterator:
cf_changes = item.get("Changes")
Expand Down Expand Up @@ -556,11 +567,28 @@ def wait_for_execute(
raise ex

def create_and_wait_for_changeset(
self, stack_name, cfn_template, parameter_values, capabilities, role_arn, notification_arns, s3_uploader, tags
self,
stack_name,
cfn_template,
parameter_values,
capabilities,
role_arn,
notification_arns,
s3_uploader,
tags,
import_existing_resources,
):
try:
result, changeset_type = self.create_changeset(
stack_name, cfn_template, parameter_values, capabilities, role_arn, notification_arns, s3_uploader, tags
stack_name,
cfn_template,
parameter_values,
capabilities,
role_arn,
notification_arns,
s3_uploader,
tags,
import_existing_resources,
)
self.wait_for_changeset(result["Id"], stack_name)
self.describe_changeset(result["Id"], stack_name)
Expand Down
7 changes: 6 additions & 1 deletion schema/samcli.json
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@
"properties": {
"parameters": {
"title": "Parameters for the deploy command",
"description": "Available parameters for the deploy command:\n* guided:\nSpecify this flag to allow SAM CLI to guide you through the deployment using guided prompts.\n* template_file:\nAWS SAM template which references built artifacts for resources in the template. (if applicable)\n* no_execute_changeset:\nIndicates whether to execute the change set. Specify this flag to view stack changes before executing the change set.\n* fail_on_empty_changeset:\nSpecify whether AWS SAM CLI should return a non-zero exit code if there are no changes to be made to the stack. Defaults to a non-zero exit code.\n* confirm_changeset:\nPrompt to confirm if the computed changeset is to be deployed by SAM CLI.\n* disable_rollback:\nPreserves the state of previously provisioned resources when an operation fails.\n* on_failure:\nProvide an action to determine what will happen when a stack fails to create. Three actions are available:\n\n- ROLLBACK: This will rollback a stack to a previous known good state.\n\n- DELETE: The stack will rollback to a previous state if one exists, otherwise the stack will be deleted.\n\n- DO_NOTHING: The stack will not rollback or delete, this is the same as disabling rollback.\n\nDefault behaviour is ROLLBACK.\n\n\n\nThis option is mutually exclusive with --disable-rollback/--no-disable-rollback. You can provide\n--on-failure or --disable-rollback/--no-disable-rollback but not both at the same time.\n* max_wait_duration:\nMaximum duration in minutes to wait for the deployment to complete.\n* stack_name:\nName of the AWS CloudFormation stack.\n* s3_bucket:\nAWS S3 bucket where artifacts referenced in the template are uploaded.\n* image_repository:\nAWS ECR repository URI where artifacts referenced in the template are uploaded.\n* image_repositories:\nMapping of Function Logical ID to AWS ECR Repository URI.\n\nExample: Function_Logical_ID=ECR_Repo_Uri\nThis option can be specified multiple times.\n* force_upload:\nIndicates whether to override existing files in the S3 bucket. Specify this flag to upload artifacts even if they match existing artifacts in the S3 bucket.\n* s3_prefix:\nPrefix name that is added to the artifact's name when it is uploaded to the AWS S3 bucket.\n* kms_key_id:\nThe ID of an AWS KMS key that is used to encrypt artifacts that are at rest in the AWS S3 bucket.\n* role_arn:\nARN of an IAM role that AWS Cloudformation assumes when executing a deployment change set.\n* use_json:\nIndicates whether to use JSON as the format for the output AWS CloudFormation template. YAML is used by default.\n* resolve_s3:\nAutomatically resolve AWS S3 bucket for non-guided deployments. Enabling this option will also create a managed default AWS S3 bucket for you. If one does not provide a --s3-bucket value, the managed bucket will be used. Do not use --guided with this option.\n* resolve_image_repos:\nAutomatically create and delete ECR repositories for image-based functions in non-guided deployments. A companion stack containing ECR repos for each function will be deployed along with the template stack. Automatically created image repositories will be deleted if the corresponding functions are removed.\n* metadata:\nMap of metadata to attach to ALL the artifacts that are referenced in the template.\n* notification_arns:\nARNs of SNS topics that AWS Cloudformation associates with the stack.\n* tags:\nList of tags to associate with the stack.\n* parameter_overrides:\nString that contains AWS CloudFormation parameter overrides encoded as key=value pairs.\n* signing_profiles:\nA string that contains Code Sign configuration parameters as FunctionOrLayerNameToSign=SigningProfileName:SigningProfileOwner Since signing profile owner is optional, it could also be written as FunctionOrLayerNameToSign=SigningProfileName\n* no_progressbar:\nDoes not showcase a progress bar when uploading artifacts to S3 and pushing docker images to ECR\n* capabilities:\nList of capabilities that one must specify before AWS Cloudformation can create certain stacks.\n\nAccepted Values: CAPABILITY_IAM, CAPABILITY_NAMED_IAM, CAPABILITY_RESOURCE_POLICY, CAPABILITY_AUTO_EXPAND.\n\nLearn more at: https://docs.aws.amazon.com/serverlessrepo/latest/devguide/acknowledging-application-capabilities.html\n* profile:\nSelect a specific profile from your credential file to get AWS credentials.\n* region:\nSet the AWS Region of the service. (e.g. us-east-1)\n* beta_features:\nEnable/Disable beta features.\n* debug:\nTurn on debug logging to print debug message generated by AWS SAM CLI and display timestamps.\n* save_params:\nSave the parameters provided via the command line to the configuration file.",
"description": "Available parameters for the deploy command:\n* guided:\nSpecify this flag to allow SAM CLI to guide you through the deployment using guided prompts.\n* template_file:\nAWS SAM template which references built artifacts for resources in the template. (if applicable)\n* no_execute_changeset:\nIndicates whether to execute the change set. Specify this flag to view stack changes before executing the change set.\n* fail_on_empty_changeset:\nSpecify whether AWS SAM CLI should return a non-zero exit code if there are no changes to be made to the stack. Defaults to a non-zero exit code.\n* confirm_changeset:\nPrompt to confirm if the computed changeset is to be deployed by SAM CLI.\n* import_existing_resources:\nRequests CloudFormation to import any existing referenced by the template when creating the changeset.\n* disable_rollback:\nPreserves the state of previously provisioned resources when an operation fails.\n* on_failure:\nProvide an action to determine what will happen when a stack fails to create. Three actions are available:\n\n- ROLLBACK: This will rollback a stack to a previous known good state.\n\n- DELETE: The stack will rollback to a previous state if one exists, otherwise the stack will be deleted.\n\n- DO_NOTHING: The stack will not rollback or delete, this is the same as disabling rollback.\n\nDefault behaviour is ROLLBACK.\n\n\n\nThis option is mutually exclusive with --disable-rollback/--no-disable-rollback. You can provide\n--on-failure or --disable-rollback/--no-disable-rollback but not both at the same time.\n* max_wait_duration:\nMaximum duration in minutes to wait for the deployment to complete.\n* stack_name:\nName of the AWS CloudFormation stack.\n* s3_bucket:\nAWS S3 bucket where artifacts referenced in the template are uploaded.\n* image_repository:\nAWS ECR repository URI where artifacts referenced in the template are uploaded.\n* image_repositories:\nMapping of Function Logical ID to AWS ECR Repository URI.\n\nExample: Function_Logical_ID=ECR_Repo_Uri\nThis option can be specified multiple times.\n* force_upload:\nIndicates whether to override existing files in the S3 bucket. Specify this flag to upload artifacts even if they match existing artifacts in the S3 bucket.\n* s3_prefix:\nPrefix name that is added to the artifact's name when it is uploaded to the AWS S3 bucket.\n* kms_key_id:\nThe ID of an AWS KMS key that is used to encrypt artifacts that are at rest in the AWS S3 bucket.\n* role_arn:\nARN of an IAM role that AWS Cloudformation assumes when executing a deployment change set.\n* use_json:\nIndicates whether to use JSON as the format for the output AWS CloudFormation template. YAML is used by default.\n* resolve_s3:\nAutomatically resolve AWS S3 bucket for non-guided deployments. Enabling this option will also create a managed default AWS S3 bucket for you. If one does not provide a --s3-bucket value, the managed bucket will be used. Do not use --guided with this option.\n* resolve_image_repos:\nAutomatically create and delete ECR repositories for image-based functions in non-guided deployments. A companion stack containing ECR repos for each function will be deployed along with the template stack. Automatically created image repositories will be deleted if the corresponding functions are removed.\n* metadata:\nMap of metadata to attach to ALL the artifacts that are referenced in the template.\n* notification_arns:\nARNs of SNS topics that AWS Cloudformation associates with the stack.\n* tags:\nList of tags to associate with the stack.\n* parameter_overrides:\nString that contains AWS CloudFormation parameter overrides encoded as key=value pairs.\n* signing_profiles:\nA string that contains Code Sign configuration parameters as FunctionOrLayerNameToSign=SigningProfileName:SigningProfileOwner Since signing profile owner is optional, it could also be written as FunctionOrLayerNameToSign=SigningProfileName\n* no_progressbar:\nDoes not showcase a progress bar when uploading artifacts to S3 and pushing docker images to ECR\n* capabilities:\nList of capabilities that one must specify before AWS Cloudformation can create certain stacks.\n\nAccepted Values: CAPABILITY_IAM, CAPABILITY_NAMED_IAM, CAPABILITY_RESOURCE_POLICY, CAPABILITY_AUTO_EXPAND.\n\nLearn more at: https://docs.aws.amazon.com/serverlessrepo/latest/devguide/acknowledging-application-capabilities.html\n* profile:\nSelect a specific profile from your credential file to get AWS credentials.\n* region:\nSet the AWS Region of the service. (e.g. us-east-1)\n* beta_features:\nEnable/Disable beta features.\n* debug:\nTurn on debug logging to print debug message generated by AWS SAM CLI and display timestamps.\n* save_params:\nSave the parameters provided via the command line to the configuration file.",
"type": "object",
"properties": {
"guided": {
Expand Down Expand Up @@ -1171,6 +1171,11 @@
"type": "boolean",
"description": "Prompt to confirm if the computed changeset is to be deployed by SAM CLI."
},
"import_existing_resources": {
"title": "import_existing_resources",
"type": "boolean",
"description": "Requests CloudFormation to import any existing referenced by the template when creating the changeset."
},
"disable_rollback": {
"title": "disable_rollback",
"type": "boolean",
Expand Down
Loading
Loading