forked from aws/aws-sam-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.py
More file actions
134 lines (121 loc) · 3.58 KB
/
Copy pathcommand.py
File metadata and controls
134 lines (121 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
CLI command for "delete" command
"""
import logging
from typing import Optional
import click
from samcli.cli.cli_config_file import ConfigProvider, configuration_option, save_params_option
from samcli.cli.main import aws_creds_options, common_options, pass_context, print_cmdline_args
from samcli.commands._utils.command_exception_handler import command_exception_handler
from samcli.commands.delete.core.command import DeleteCommand
from samcli.commands.delete.delete_context import CONFIG_COMMAND, CONFIG_SECTION
from samcli.lib.telemetry.metric import track_command
from samcli.lib.utils.version_checker import check_newer_version
SHORT_HELP = "Delete an AWS SAM application and the artifacts created by sam deploy."
HELP_TEXT = """The sam delete command deletes the CloudFormation
stack and all the artifacts which were created using sam deploy.
"""
DESCRIPTION = """
Delete an AWS SAM application by deleting the AWS CloudFormation stack,
the artifacts which were packaged and deployed to Amazon S3 and Amazon ECR,
and the AWS CloudFormation template file from the Amazon S3 bucket.
"""
LOG = logging.getLogger(__name__)
@click.command(
"delete",
cls=DeleteCommand,
short_help=SHORT_HELP,
help=HELP_TEXT,
description=DESCRIPTION,
requires_credentials=True,
context_settings={"ignore_unknown_options": False, "allow_interspersed_args": True, "allow_extra_args": True},
)
@configuration_option(provider=ConfigProvider(CONFIG_SECTION, [CONFIG_COMMAND]))
@click.option(
"--stack-name",
required=False,
help="The name of the AWS CloudFormation stack you want to delete. ",
)
@click.option(
"--no-prompts",
help=("Specify this flag to allow SAM CLI to skip through the guided prompts."),
is_flag=True,
required=False,
)
@click.option(
"--s3-bucket",
help=("The S3 bucket path you want to delete."),
type=click.STRING,
default=None,
required=False,
)
@click.option(
"--s3-prefix",
help=("The S3 prefix you want to delete"),
type=click.STRING,
default=None,
required=False,
)
@click.option(
"--express/--no-express",
default=False,
required=False,
is_flag=True,
help="Use CloudFormation Express mode to speed up stack deletion by completing once resource "
"deletion is initiated, without waiting for full cleanup.",
)
@aws_creds_options
@common_options
@save_params_option
@pass_context
@track_command
@check_newer_version
@print_cmdline_args
@command_exception_handler
def cli(
ctx,
stack_name: str,
no_prompts: bool,
s3_bucket: str,
s3_prefix: str,
express: bool,
config_env: str,
config_file: str,
save_params: bool,
):
"""
`sam delete` command entry point
"""
# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing
do_cli(
stack_name=stack_name,
region=ctx.region,
profile=ctx.profile,
no_prompts=no_prompts,
s3_bucket=s3_bucket,
s3_prefix=s3_prefix,
express=express,
) # pragma: no cover
def do_cli(
stack_name: str,
region: str,
profile: str,
no_prompts: bool,
s3_bucket: Optional[str],
s3_prefix: Optional[str],
express: bool = False,
):
"""
Implementation of the ``cli`` method
"""
from samcli.commands.delete.delete_context import DeleteContext
with DeleteContext(
stack_name=stack_name,
region=region,
profile=profile,
no_prompts=no_prompts,
s3_bucket=s3_bucket,
s3_prefix=s3_prefix,
express=express,
) as delete_context:
delete_context.run()