Skip to content

Instantly share code, notes, and snippets.

@rdsedmundo
Created July 7, 2020 20:59
Show Gist options
  • Save rdsedmundo/8b07ea5d33a90b5cd7fa67fe92bae28e to your computer and use it in GitHub Desktop.
Save rdsedmundo/8b07ea5d33a90b5cd7fa67fe92bae28e to your computer and use it in GitHub Desktop.
Deletes all lambda layers and their versions
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