def deploy(kctx: kitipy.Context, version: str): """Deploy a given version to ECS.""" client = kitipy.libs.aws.ecs.new_client() stack = kctx.config["stacks"][kctx.stack.name] cluster_name = kctx.stage["ecs_cluster_name"] service_name = versioned_service_name(stack) service_def = stack["ecs_service_definition"](kctx) task_def = stack["ecs_task_definition"](kctx) task_def["containerDefinitions"] = stack["ecs_container_transformer"]( kctx, version) task_def_tags = task_def.get("tags", []) task_def_tags.append({'key': 'kitipy.image_tag', 'value': version}) task_def["tags"] = task_def_tags try: deployment_id = kitipy.libs.aws.ecs.upsert_service( client, cluster_name, service_name, task_def, service_def) except kitipy.libs.aws.ecs.ServiceDefinitionChangedError as err: kctx.fail( "Could not deploy the API: ECS service definition has " + "changed - {0}. You have to increment the version ".format(err) + "number in the ./tasks.py file before re-running this command.\n") for event in kitipy.libs.aws.ecs.watch_deployment(client, cluster_name, service_name, deployment_id): createdAt = event["createdAt"].isoformat() message = event["message"] kctx.info("[{createdAt}] {message}".format(createdAt=createdAt, message=message))
def edit(kctx: kitipy.Context, secret_name): """Edit secrets stored by AWS Secrets Manager.""" stack = kctx.config['stacks'][kctx.stack.name] secret_arn = stack['secret_arn_resolver'](kctx=kctx, secret_name=secret_name) client = sm.new_client() secret = sm.describe_secret_with_current_value(client, secret_arn) if secret == None: kctx.fail("Secret \"%s\" not found." % (secret_name)) value = click.edit(text=secret['SecretString']) if value == None: kctx.info("Secret value was not changed. Aborting.") raise click.exceptions.Abort() trim_question = ("Your secret value ends with a new line. This is " + "generally abnormal. Would you want to trim it " + "automatically?") if value.endswith("\n") and click.confirm(trim_question, default=True): value = value.rstrip("\n") kctx.echo(("NOTE: Secret values end with %s. This is here to help you " + "see invisible characters (e.g. whitespace, line breaks, " + "etc...).\n") % (secret_delimiter)) kctx.echo("ID: %s" % (secret["ARN"])) kctx.echo("Name: %s" % (secret["Name"])) kctx.echo("Previous value: %s" % (format_secret_value(secret["SecretString"], True))) kctx.echo("New value: %s" % (format_secret_value(value, True))) click.confirm("\nDo you confirm this change?", abort=True) sm.put_secret_value(client, secret["ARN"], value)