Created
September 22, 2021 09:15
-
-
Save r-plus/5e1a20c603fb6e363f804d2480efd65f to your computer and use it in GitHub Desktop.
add tag name to all lambda functions
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
#!/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