o .&a7@sddlZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZddlmZdd lmZeeZGd d d eZdS) N)Config) exceptions)Deployer) S3Uploader) yaml_parse) BasicCommand)get_stdout_text_writer)write_exceptionc@s4eZdZdZdZdZdZdZe ddZ dd d d d d d dddddd dddddddddded ddddidgd d!d"d dddd#d$gd%dgd&d!d'd(d)dd*d+d,dd-d d.ddddidd/d0d1ddd1d2d d3d4d5dd(d1d2d d6d4ed ddddidgd7d!gZ d8d9Z dAd:d;Z dd?Zd@S)B DeployCommandzChangeset created successfully. Run the following command to review changes: aws cloudformation describe-change-set --change-set-name {changeset_id} z2Successfully created/updated stack - {stack_name} zparameter-overridestagsdeploycloudformationz_deploy_description.rstz template-fileTz;The path where your AWS CloudFormation template is located.)namerequired help_textz stack-namestorezThe name of the AWS CloudFormation stack you're deploying to. If you specify an existing stack, the command updates the stack. If you specify a new stack, the command creates it.)ractionrrz s3-bucketFzThe name of the S3 bucket where this command uploads your CloudFormation template. This is required the deployments of templates sized greater than 51,200 bytesz force-upload store_truezIndicates 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.)rrrz s3-prefixzA prefix name that the command adds to the artifacts' name when it uploads them to the S3 bucket. The prefix name is a path name (folder name) for the S3 bucket.)rrz kms-key-idzfThe ID of an AWS KMS key that the command uses to encrypt artifacts that are at rest in the S3 bucket.arraytypestring)ritemsaUA list of parameter structures that specify input parameters for your stack template. If you're updating a stack and you don't specify a parameter, the command uses the stack's existing value. For new stacks, you must specify parameters that don't have a default value. Syntax: ParameterKey1=ParameterValue1 ParameterKey2=ParameterValue2 ...)rrrschemadefaultr capabilitiesCAPABILITY_IAMCAPABILITY_NAMED_IAM)renumaA list of capabilities that you must specify before AWS Cloudformation can create certain stacks. Some stack templates might include resources that can affect permissions in your AWS account, for example, by creating new AWS Identity and Access Management (IAM) users. For those stacks, you must explicitly acknowledge their capabilities by specifying this parameter. The only valid values are CAPABILITY_IAM and CAPABILITY_NAMED_IAM. If you have IAM resources, you can specify either capability. If you have IAM resources with custom names, you must specify CAPABILITY_NAMED_IAM. If you don't specify this parameter, this action returns an InsufficientCapabilities error.zno-execute-changeset store_falseexecute_changeseta1Indicates whether to execute the change set. Specify this flag if you want to view your stack changes before executing the change set. The command creates an AWS CloudFormation change set and then exits without executing the change set. After you view the change set, execute it to implement your changes.)rrdestrrzrole-arnzThe Amazon Resource Name (ARN) of an AWS Identity and Access Management (IAM) role that AWS CloudFormation assumes when executing the change set.znotification-arnszxAmazon Simple Notification Service topic Amazon Resource Names (ARNs) that AWS CloudFormation associates with the stack.)rrrrzfail-on-empty-changesetfail_on_empty_changesetzSpecify if the CLI should return a non-zero exit code if there are no changes to be made to the stack. The default behavior is to return a non-zero exit code.)rrr group_namer rrzno-fail-on-empty-changesetz[Causes the CLI to return an exit code of 0 if there are no changes to be made to the stack.zA list of tags to associate with the stack that is created or updated. AWS CloudFormation also propagates these tags to resources in the stack if the resource supports it. Syntax: TagKey1=TagValue1 TagKey2=TagValue2 ...c CsN|jjd|j|j|jd}|j}tj|st j |dt |d }| }Wdn1s0wY|j }||j|j}||j|j} dd| D} t|} || |} tj|j} | dkrm|jsmt |j}|r|jjdtd d |j|jd }t|||j|j|j}nd}t|}||||| |j |j!|j"|j#|| |j$ S) Nr ) region_name endpoint_urlverify) template_pathrcSsg|] \}}||dqS))KeyValue).0keyvaluer*r*M/usr/lib/python3/dist-packages/awscli/customizations/cloudformation/deploy.py sz+DeployCommand._run_main..is3s3v4)signature_version)configr#r%)%_session create_clientregionr$ verify_ssl template_fileospathisfilerInvalidTemplatePathErroropenread stack_nameparse_key_value_argparameter_overridesPARAMETER_OVERRIDE_CMDr TAGS_CMDrrmerge_parametersgetsize s3_bucketDeployBucketRequiredErrorrr s3_prefix kms_key_id force_uploadrr rrrole_arnnotification_arnsr!)self parsed_argsparsed_globalscloudformation_clientr&handle template_strr?rA tags_dictr template_dict parameters template_sizebucket s3_client s3_uploaderdeployerr*r*r. _run_mainsf     zDeployCommand._run_mainc  Csz|j||||||| | d} Wntjy-} z| rt| tdWYd} ~ dSd} ~ ww|rJ|| j|||| jt j |j j |dn t j |jj | jdt j dS)N)r? cfn_templateparameter_valuesrrKrLrYr )outfiler)r?) changeset_id)create_and_wait_for_changesetrChangeEmptyErrorr rrr_wait_for_executechangeset_typesysstdoutwriteMSG_EXECUTE_SUCCESSformatMSG_NO_EXECUTE_CHANGESETflush)rMrZr?rRrUrrrKrLrYr r!resultexr*r*r.r )s:     zDeployCommand.deploycCsdg}t|ddts |S|dD]\}}d|i}||vr&|||d<nd|d<||q|S)a CloudFormation CreateChangeset requires a value for every parameter from the template, either specifying a new value or use previous value. For convenience, this method will accept new parameter values and generates a dict of all parameters in a format that ChangeSet API will accept :param parameter_overrides: :return: ParametersN ParameterKeyParameterValueTUsePreviousValue) isinstancegetdictrappend)rMrTrAr]r,r-objr*r*r.rDJs  zDeployCommand.merge_parameterscCsHi}|D]}|dd}t|dkrtj||d|d||d<q|S)af Converts arguments that are passed as list of "Key=Value" strings into a real dictionary. :param arg_value list: Array of strings, where each string is of form Key=Value :param argname string: Name of the argument that contains the value :return dict: Dictionary representing the key/value pairs =)argnamer-r)splitlenr InvalidKeyValuePairArgumentError)rM arg_valueryrkdatakey_value_pairr*r*r.r@is   z!DeployCommand.parse_key_value_argN)T)__name__ __module__ __qualname__rirgrBrCNAMEr FROM_FILE DESCRIPTION ARG_TABLEr[r rDr@r*r*r*r.r s      !  >< ! r )r9rdloggingbotocore.clientr$awscli.customizations.cloudformationr-awscli.customizations.cloudformation.deployerr awscli.customizations.s3uploaderr/awscli.customizations.cloudformation.yamlhelperrawscli.customizations.commandsr awscli.compatr awscli.utilsr getLoggerrLOGr r*r*r*r.s