Created
March 29, 2023 19:38
-
-
Save devxoul/9d53a9ecc7762c783a8afc248c9b9971 to your computer and use it in GitHub Desktop.
Delete AWS Lambda function revisions in parallel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import subprocess | |
import time | |
from asgiref.sync import sync_to_async | |
async def delete_revision(function_name, revision): | |
cmd = f"aws lambda delete-function --function-name {function_name}:{revision}" | |
print(cmd) | |
await sync_to_async(subprocess.Popen)(cmd, shell=True) | |
async def main(function_name, revision_from, revision_to): | |
BATCH_SIZE = 10 | |
tasks = [] | |
for revision in range(revision_from, revision_to + 1): | |
tasks.append(delete_revision(function_name, revision)) | |
if len(tasks) >= BATCH_SIZE: | |
await asyncio.gather(*tasks) | |
tasks = [] | |
time.sleep(1) | |
if tasks: | |
await asyncio.gather(*tasks) | |
asyncio.run(main("my_function_name", 12, 345)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment