Skip to content

Instantly share code, notes, and snippets.

@devxoul
Created March 29, 2023 19:38
Show Gist options
  • Save devxoul/9d53a9ecc7762c783a8afc248c9b9971 to your computer and use it in GitHub Desktop.
Save devxoul/9d53a9ecc7762c783a8afc248c9b9971 to your computer and use it in GitHub Desktop.
Delete AWS Lambda function revisions in parallel
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