aws_helpers.py
def create_repository(repository_name="stockholm-ai"):
    """Create new ecr repository with lifecycle policy."""
    ecr_client = boto3.client("ecr")

    # This is not very elegant.
    try:
        repo = ecr_client.create_repository(repositoryName=repository_name)
        lifecycle_policy = """{
          "rules": [
            {
              "rulePriority": 10,
              "description": "Delete untagged",
              "selection": {
                "tagStatus": "untagged",
                "countType": "imageCountMoreThan",
                "countNumber": 3
              },
              "action": {
                "type": "expire"
              }
            }
          ]
        }"""
        ecr_client.put_lifecycle_policy(
            repositoryName=repository_name,
            lifecyclePolicyText=lifecycle_policy)
    except:
        repo = ecr_client.describe_repositories(
            repositoryNames=[repository_name])

    return repo
Create new ecr repository with lifecycle policy.
Create new ecr repository with lifecycle policy.
Create new ecr repository with lifecycle policy .
def create_repository(repository_name="stockholm-ai"):
    ecr_client = boto3.client("ecr")
    try:
        repo = ecr_client.create_repository(repositoryName=repository_name)
        lifecycle_policy = """{
          "rules": [
            {
              "rulePriority": 10,
              "description": "Delete untagged",
              "selection": {
                "tagStatus": "untagged",
                "countType": "imageCountMoreThan",
                "countNumber": 3
              },
              "action": {
                "type": "expire"
              }
            }
          ]
        }"""
        ecr_client.put_lifecycle_policy(
            repositoryName=repository_name,
            lifecyclePolicyText=lifecycle_policy)
    except:
        repo = ecr_client.describe_repositories(
            repositoryNames=[repository_name])
    return repo
def create_repository ( repository_name = "stockholm-ai" ) : ecr_client = boto3 . client ( "ecr" ) try : repo = ecr_client . create_repository ( repositoryName = repository_name ) lifecycle_policy = """{
          "rules": [
            {
              "rulePriority": 10,
              "description": "Delete untagged",
              "selection": {
                "tagStatus": "untagged",
                "countType": "imageCountMoreThan",
                "countNumber": 3
              },
              "action": {
                "type": "expire"
              }
            }
          ]
        }""" ecr_client . put_lifecycle_policy ( repositoryName = repository_name , lifecyclePolicyText = lifecycle_policy ) except : repo = ecr_client . describe_repositories ( repositoryNames = [ repository_name ] ) return repo
Create new ecr repository with lifecycle policy.
Create new ecr repository with lifecycle policy .
"""Create new ecr repository with lifecycle policy.""" # This is not very elegant.
repository_name