Skip to content

Instantly share code, notes, and snippets.

@yusufhm
Created August 30, 2018 02:03
Show Gist options
  • Select an option

  • Save yusufhm/8b75cde2393d41b751a0b644dd28d96f to your computer and use it in GitHub Desktop.

Select an option

Save yusufhm/8b75cde2393d41b751a0b644dd28d96f to your computer and use it in GitHub Desktop.
Get the last commit of a Lambda function in Python
#!/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