Created
August 30, 2018 02:03
-
-
Save yusufhm/8b75cde2393d41b751a0b644dd28d96f to your computer and use it in GitHub Desktop.
Get the last commit of a Lambda function in Python
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 python | |
| import sys | |
| import boto3 | |
| import os | |
| def get_lambda_last_commit(arn): | |
| """Get the commit hash of the last lambda push. | |
| Keyword arguments: | |
| arn -- The lambda function arn. | |
| """ | |
| client = boto3.client('lambda', | |
| region_name='ap-southeast-2', | |
| aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID'), | |
| aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY') | |
| ) | |
| response = client.list_tags(Resource=arn) | |
| if not 'Tags' in response: | |
| return None | |
| if not 'vcs-ref' in response['Tags']: | |
| return None | |
| return response['Tags']['vcs-ref'] | |
| def main(): | |
| arn = sys.argv[1] | |
| print get_lambda_last_commit(arn) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment