Created
January 2, 2020 14:01
-
-
Save bahrmichael/95f68843dcc8cf70e7c5e666c446b0f8 to your computer and use it in GitHub Desktop.
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 sys | |
| import boto3 | |
| region = 'us-east-1' | |
| target_tag = 'project' | |
| client = boto3.client('lambda', region) | |
| functions = client.list_functions().get('Functions', []) | |
| for function in functions: | |
| tags = client.list_tags(Resource=function['FunctionArn']).get('Tags', []) | |
| if target_tag not in tags: | |
| print(f"Lambda {function['FunctionArn']} is missing tag {target_tag}") | |
| tag_value = None | |
| if 'aws-scheduler' in function['FunctionArn']: | |
| tag_value = 'serverless-scheduler' | |
| elif 'testing-mail' in function['FunctionArn']: | |
| tag_value = 'research' | |
| if tag_value is not None: | |
| client.tag_resource(Resource=function['FunctionArn'], Tags={target_tag: tag_value}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment