Git Product home page Git Product logo

aws-lambda-ecr-cleaner's Introduction

drawing

AWS lambda ecr cleaner

Code Climate JavaScript Style Guide Coverage Status Build

An AWS Lambda Function to clean ecr repos automatically.

Requirements

  • node.js ( AWS Lambda working version is 4.3.2 )

Installation

Clone this repository and install dependencies:

$ git clone [email protected]:Puemos/aws-lambda-ecr-cleaner.git
$ cd aws-lambda-ecr-cleaner
$ npm install

Packaging

AWS Lambda accepts zip archived package. To create it, run npm run package task simply.

$ npm run package --packageDirectory=./dist

It will create aws-lambda-ecr-cleaner.zip at project root. You can upload it.

Configuration

Hardcode the configuration on config.json

Name Type Description Default
DRY_RUN Bool Run without delete true
API_DELAY Integer Delay between calls 500
REPO_AGE_THRESHOLD Integer Image age threshold 90
REPO_FIRST_N_THRESHOLD Integer How many images from each group to keep 3
AWS_ACCOUNT_ID Integer The account id number
REGION String ECR and ECS region. us-east-1
REPO_TO_CLEAN String / Array String One repo name or an array of repos name to clean
ENVS Array String Group by these strings and one for each unique tag

Lambda IAM Role

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "LambdaBasicExecution",
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "*"
        },
        {
            "Action": [
                "ecr:BatchDeleteImage",
                "ecr:ListImages",
                "ecr:DescribeImages",
            ],
            "Effect": "Allow",
            "Resource": "*"
        },
        {
            "Action": [
                "ecs:DescribeTaskDefinition",
                "ecs:ListTaskDefinitions"
            ],
            "Effect": "Allow",
            "Resource": "*"
        }
    ]
}

For a more restrictive policy, you can specify the resources. See ARNs and Namespace docs for complete list.

  • ECR Resources:
    • "arn:aws:ecr:region:account:repository/my-repo"
    • "arn:aws:ecr:region:account:repository/develop-*"
  • ECS Resources
    • "arn:aws:ecs:region:account-id:task-definition/task-definition-family-name:task-definition-revision-number"
    • "arn:aws:ecs:region:account-id:task-definition/task-definition-family-name:*"
    • "arn:aws:ecs:region:account-id:task-definition/*"

License

MIT License @ Shy Alter

Credits

aws-lambda-ecr-cleaner's People

Contributors

jveldboom avatar puemos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aws-lambda-ecr-cleaner's Issues

cannot read property '0' of undefined

Hi,
many thanks for your project. I use it for last couple of weeks. This is more request for help than bug report....

Since 4th of Jan 2017 your aws-lambda-ecr-cleaner starts failing on error
{"errorMessage":"Cannot read property '0' of undefined","errorType":"TypeError","stackTrace":["/var/task/lib/index.js:152:37","Array.map (native)","/var/task/lib/index.js:149:18","tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23)","Promise._settlePromiseFromHandler (/var/task/node_modules/bluebird/js/release/promise.js:510:31)","Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:567:18)","Promise._settlePromise0 (/var/task/node_modules/bluebird/js/release/promise.js:612:10)","Promise._settlePromises (/var/task/node_modules/bluebird/js/release/promise.js:691:18)","Promise._fulfill (/var/task/node_modules/bluebird/js/release/promise.js:636:18)","Response.<anonymous> (/var/task/node_modules/bluebird/js/release/nodeback.js:42:21)","Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:355:18)","Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:105:20)","Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:77:10)","Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:668:14)","Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)","AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)"]}

Do you have any idea what could be wrong? I'm not aware of any changes made in code nor in AWS...Do you also use this project? can you try to run it today to see if it works for you or not?

Thanks
Martin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.