{"id":20770744,"url":"https://github.com/codemonauts/ami-updater","last_synced_at":"2025-12-25T05:13:20.382Z","repository":{"id":82653619,"uuid":"223982595","full_name":"codemonauts/ami-updater","owner":"codemonauts","description":"Create new LaunchConfigurations with a new AMI","archived":false,"fork":false,"pushed_at":"2025-07-11T10:37:43.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-11T13:27:11.351Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codemonauts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-25T15:35:56.000Z","updated_at":"2025-07-11T10:37:47.000Z","dependencies_parsed_at":"2024-05-13T06:44:30.720Z","dependency_job_id":null,"html_url":"https://github.com/codemonauts/ami-updater","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codemonauts/ami-updater","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonauts%2Fami-updater","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonauts%2Fami-updater/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonauts%2Fami-updater/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonauts%2Fami-updater/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemonauts","download_url":"https://codeload.github.com/codemonauts/ami-updater/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonauts%2Fami-updater/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28020176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-25T02:00:05.988Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T12:11:43.108Z","updated_at":"2025-12-25T05:13:20.374Z","avatar_url":"https://github.com/codemonauts.png","language":"Python","readme":"# ami-updater\n\nLittle Lambda script to update all your EC2 launch configurations after building a new AMI.\n\n## Description\n\nThe Lambda function searchs for all existing Launch Templates. If the Launch Template has a tag `ami-search-string`, all AMIs with the value of the tag will be considered as possible AMIs to use. Then it checks if there is a new AMI available (creation time) and creates a new default version with the new AMI.\n\nAfter this, all versions withing the retension policy will be kept, all older versions and their AMIs and snapshots will be deleted.\n\n### Search Tag\n\nThe template tag `ami-search-string` is used to find all possible AMIs by the defined name. You can use wildcards like `webserver_*`.\n\n### Retension policy\n\nIn the Lambda function, you can add an environment variable called `KEEP_AMIS` to set the maximal versions to keep (including the new version created). The default value is 3.\n\n## Installation by hand\n\n### Role and policy\n\nCreate a role for the Lambda function and add the following policy. Please replace the `\u003cREGION\u003e` and `\u003cACCOUNTID\u003e` with your values.\n\n```json\n{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n        {\n            \"Effect\": \"Allow\",\n            \"Action\": \"ec2:DeregisterImage\",\n            \"Resource\": \"arn:aws:ec2:\u003cREGION\u003e::image/*\"\n        },\n        {\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"ec2:DescribeImages\",\n                \"ec2:DescribeLaunchTemplates\",\n                \"ec2:DescribeLaunchTemplateVersions\"\n            ],\n            \"Resource\": \"*\"\n        },\n        {\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"ec2:ModifyLaunchTemplate\",\n                \"ec2:DeleteLaunchTemplateVersions\",\n                \"ec2:CreateLaunchTemplateVersion\"\n            ],\n            \"Resource\": \"arn:aws:ec2:\u003cREGION\u003e:\u003cACCOUNTID\u003e:launch-template/*\"\n        },\n        {\n            \"Effect\": \"Allow\",\n            \"Action\": \"ec2:DeleteSnapshot\",\n            \"Resource\": \"arn:aws:ec2:*::snapshot/*\"\n        },\n        {\n            \"Effect\": \"Allow\",\n            \"Action\": \"logs:CreateLogGroup\",\n            \"Resource\": \"arn:aws:logs:\u003cREGION\u003e:\u003cACCOUNTID\u003e:*\"\n        },\n        {\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"logs:CreateLogStream\",\n                \"logs:PutLogEvents\"\n            ],\n            \"Resource\": [\n                \"arn:aws:logs:\u003cREGION\u003e:\u003cACCOUNTID\u003e:log-group:/aws/lambda/ami-updater:*\"\n            ]\n        }\n    ]\n}\n```\n\n### Build package for Lambda\n\nRun the following command to build a `package.zip` with the code for the Lambda function. \n\n```shell\nmake build\n```\n\n### Lambda function\n\nYou can create the Lambda function with the console. The following settings are recommended:\n\n- Timeout wit 60 seconds or more (depends on the number of Launch templates to check).\n- Runtime is Python 3.11 or newer.\n- The handler is `main.lambda_handler`.\n- Architecture can be `arm64` or `x86_64`.\n- Add an environment variable `KEEP_AMIS` with the value of the number of AMIs to keep per Launch Template. Default is 3.\n\nOr create a Lambda function with the AWS CLI. Replace the `\u003cARN\u003e` with the ARN of the role created above:\n\n```shell\naws lambda create-function \\\n    --function-name ami-updater \\\n    --runtime python3.11 \\\n    --zip-file fileb://package.zip \\\n    --handler main.lambda_handler \\\n    --timeout 60 \\\n    --publish \\\n    --architectures arm64 \\\n    --role \u003cARN\u003e\n```\n\nYou have now a Lambda function without a trigger. We suggest to use an EventBridge schedule rule or the EventBridge Scheduler.\n\n## Installation by Terraform\n\nYou can use the `main.tf` to\n\n- Create all roles.\n- A log group.\n- The Lambda function itself.\n- A scheduler to invoke the Lambda function at a 12 hours rate.\n\nIf you know what you do, you can do:\n\n```shell\nmake build\nmake plan\nmake deploy\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemonauts%2Fami-updater","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemonauts%2Fami-updater","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemonauts%2Fami-updater/lists"}