Skip to content

Instantly share code, notes, and snippets.

@r-plus
Created September 22, 2021 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-plus/5e1a20c603fb6e363f804d2480efd65f to your computer and use it in GitHub Desktop.
Save r-plus/5e1a20c603fb6e363f804d2480efd65f to your computer and use it in GitHub Desktop.
add tag name to all lambda functions
#!/usr/bin/env zx
const aws = require('aws-sdk');
const lambda = new aws.Lambda({ region: 'ap-northeast-1' });
const functions = await lambda.listFunctions().promise();
for (const f of functions.Functions) {
const str = await $`aws lambda list-tags --resource ${f.FunctionArn}`
const json = JSON.parse(str);
json.Tags.Name = f.FunctionName;
const tag = Object.entries(json.Tags)
.filter(([key, value]) => !key.startsWith('aws:'))
.map(([key, value]) => `${key}=${value}`)
.join(",");
await $`aws lambda tag-resource --resource ${f.FunctionArn} --tags ${tag}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment