def guided_prompts(self, parameter_override_keys): default_stack_name = self.stack_name or "sam-app" default_region = self.region or "us-east-1" default_capabilities = ("CAPABILITY_IAM", ) input_capabilities = None click.echo( self.color.yellow( "\n\tSetting default arguments for 'sam deploy'\n\t=========================================" )) stack_name = prompt(f"\t{self.start_bold}Stack Name{self.end_bold}", default=default_stack_name, type=click.STRING) region = prompt(f"\t{self.start_bold}AWS Region{self.end_bold}", default=default_region, type=click.STRING) input_parameter_overrides = self.prompt_parameters( parameter_override_keys, self.start_bold, self.end_bold) click.secho( "\t#Shows you resources changes to be deployed and require a 'Y' to initiate deploy" ) confirm_changeset = confirm( f"\t{self.start_bold}Confirm changes before deploy{self.end_bold}", default=self.confirm_changeset) click.secho( "\t#SAM needs permission to be able to create roles to connect to the resources in your template" ) capabilities_confirm = confirm( f"\t{self.start_bold}Allow SAM CLI IAM role creation{self.end_bold}", default=True) if not capabilities_confirm: input_capabilities = prompt( f"\t{self.start_bold}Capabilities{self.end_bold}", default=list(default_capabilities), type=FuncParamType(func=_space_separated_list_func_type), ) self.prompt_authorization(input_parameter_overrides) save_to_config = confirm( f"\t{self.start_bold}Save arguments to samconfig.toml{self.end_bold}", default=True) s3_bucket = manage_stack(profile=self.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") self.guided_stack_name = stack_name self.guided_s3_bucket = s3_bucket self.guided_s3_prefix = stack_name self.guided_region = region self.guided_profile = self.profile self._capabilities = input_capabilities if input_capabilities else default_capabilities self._parameter_overrides = input_parameter_overrides if input_parameter_overrides else self.parameter_overrides self.save_to_config = save_to_config self.confirm_changeset = confirm_changeset
def notification_arns_click_option(): return click.option( "--notification-arns", cls=OptionNargs, type=FuncParamType(func=_space_separated_list_func_type), required=False, help="Amazon Simple Notification Service topic" "Amazon Resource Names (ARNs) that AWS CloudFormation associates with" "the stack.", )
def guided_deploy( stack_name, s3_bucket, region, profile, confirm_changeset, parameter_override_keys, parameter_overrides ): default_stack_name = stack_name or "sam-app" default_region = region or "us-east-1" default_capabilities = ("CAPABILITY_IAM",) input_capabilities = None color = Colored() start_bold = "\033[1m" end_bold = "\033[0m" click.echo( color.yellow("\n\tSetting default arguments for 'sam deploy'\n\t=========================================") ) stack_name = click.prompt(f"\t{start_bold}Stack Name{end_bold}", default=default_stack_name, type=click.STRING) s3_prefix = stack_name region = click.prompt(f"\t{start_bold}AWS Region{end_bold}", default=default_region, type=click.STRING) input_parameter_overrides = prompt_parameters(parameter_override_keys, start_bold, end_bold) click.secho("\t#Shows you resources changes to be deployed and require a 'Y' to initiate deploy") confirm_changeset = click.confirm( f"\t{start_bold}Confirm changes before deploy{end_bold}", default=confirm_changeset ) click.secho("\t#SAM needs permission to be able to create roles to connect to the resources in your template") capabilities_confirm = click.confirm(f"\t{start_bold}Allow SAM CLI IAM role creation{end_bold}", default=True) if not capabilities_confirm: input_capabilities = click.prompt( f"\t{start_bold}Capabilities{end_bold}", default=default_capabilities[0], type=FuncParamType(func=_space_separated_list_func_type), ) save_to_config = click.confirm(f"\t{start_bold}Save arguments to samconfig.toml{end_bold}", default=True) 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") return ( stack_name, s3_bucket, s3_prefix, region, profile, confirm_changeset, input_capabilities if input_capabilities else default_capabilities, input_parameter_overrides if input_parameter_overrides else parameter_overrides, save_to_config, )
def capabilities_click_option(): return click.option( "--capabilities", cls=OptionNargs, required=False, type=FuncParamType(func=_space_separated_list_func_type), help="A list of capabilities that you must specify" "before AWS Cloudformation can create certain stacks. Some stack tem-" "plates might include resources that can affect permissions in your AWS" "account, for example, by creating new AWS Identity and Access Manage-" "ment (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 cus-" "tom names, you must specify CAPABILITY_NAMED_IAM. If you don't specify" "this parameter, this action returns an InsufficientCapabilities error.", )
def guided_prompts(self, parameter_override_keys): default_stack_name = self.stack_name or "sam-app" default_region = self.region or get_session().get_config_variable( "region") or "us-east-1" default_capabilities = self.capabilities[0] or ("CAPABILITY_IAM", ) default_config_env = self.config_env or DEFAULT_ENV default_config_file = self.config_file or DEFAULT_CONFIG_FILE_NAME input_capabilities = None config_env = None config_file = None click.echo( self.color.yellow( "\n\tSetting default arguments for 'sam deploy'\n\t=========================================" )) stack_name = prompt(f"\t{self.start_bold}Stack Name{self.end_bold}", default=default_stack_name, type=click.STRING) region = prompt(f"\t{self.start_bold}AWS Region{self.end_bold}", default=default_region, type=click.STRING) input_parameter_overrides = self.prompt_parameters( parameter_override_keys, self.parameter_overrides_from_cmdline, self.start_bold, self.end_bold) stacks = SamLocalStackProvider.get_stacks( self.template_file, parameter_overrides=sanitize_parameter_overrides( input_parameter_overrides)) image_repositories = self.prompt_image_repository(stacks) click.secho( "\t#Shows you resources changes to be deployed and require a 'Y' to initiate deploy" ) confirm_changeset = confirm( f"\t{self.start_bold}Confirm changes before deploy{self.end_bold}", default=self.confirm_changeset) click.secho( "\t#SAM needs permission to be able to create roles to connect to the resources in your template" ) capabilities_confirm = confirm( f"\t{self.start_bold}Allow SAM CLI IAM role creation{self.end_bold}", default=True) if not capabilities_confirm: input_capabilities = prompt( f"\t{self.start_bold}Capabilities{self.end_bold}", default=list(default_capabilities), type=FuncParamType(func=_space_separated_list_func_type), ) self.prompt_authorization(stacks) self.prompt_code_signing_settings(stacks) save_to_config = confirm( f"\t{self.start_bold}Save arguments to configuration file{self.end_bold}", default=True) if save_to_config: config_file = prompt( f"\t{self.start_bold}SAM configuration file{self.end_bold}", default=default_config_file, type=click.STRING, ) config_env = prompt( f"\t{self.start_bold}SAM configuration environment{self.end_bold}", default=default_config_env, type=click.STRING, ) s3_bucket = manage_stack(profile=self.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") self.guided_stack_name = stack_name self.guided_s3_bucket = s3_bucket self.guided_image_repositories = image_repositories self.guided_s3_prefix = stack_name self.guided_region = region self.guided_profile = self.profile self._capabilities = input_capabilities if input_capabilities else default_capabilities self._parameter_overrides = (input_parameter_overrides if input_parameter_overrides else self.parameter_overrides_from_cmdline) self.save_to_config = save_to_config self.config_env = config_env if config_env else default_config_env self.config_file = config_file if config_file else default_config_file self.confirm_changeset = confirm_changeset