Created
July 7, 2020 20:59
-
-
Save rdsedmundo/8b07ea5d33a90b5cd7fa67fe92bae28e to your computer and use it in GitHub Desktop.
Deletes all lambda layers and their versions
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 { Lambda } from 'aws-sdk'; | |
const lambda = new Lambda({ region: 'us-east-1' }); | |
async function run() { | |
const { Layers: layers } = await lambda.listLayers().promise(); | |
if (!layers) { | |
console.log('No layers to delete.'); | |
return; | |
} | |
/* eslint-disable no-await-in-loop */ | |
for (const layer of layers) { | |
// TODO: seek all records through pagination | |
const { LayerVersions: versions } = await lambda | |
.listLayerVersions({ LayerName: layer.LayerName }) | |
.promise(); | |
for (const version of versions) { | |
console.log(`Deleting ${layer.LayerName}:${version.Version}`); | |
await lambda | |
.deleteLayerVersion({ | |
LayerName: layer.LayerName, | |
VersionNumber: version.Version, | |
}) | |
.promise(); | |
} | |
} | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment