Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
Created January 11, 2017 11:22
Show Gist options
  • Save wehappyfew/bb829c17fdbbe188726e374814f742b9 to your computer and use it in GitHub Desktop.
Save wehappyfew/bb829c17fdbbe188726e374814f742b9 to your computer and use it in GitHub Desktop.
A lambda function that checks for the latest Terraform release
import boto3,requests,json,os,pprint
from bs4 import BeautifulSoup
tf_github_url = os.environ["target_url"] #"https://github.com/hashicorp/terraform/releases"
sns_topic_arn = os.environ["sns_topic_arn"] # eg arn:aws:sns:us-west-2:account-id:Report_terra_version
def post_to_SNS(SNS_topic_ARN, msg):
client = boto3.client('sns')
response = client.publish(
TopicArn = SNS_topic_ARN,
Message = json.dumps(
{'default': json.dumps(msg)}
),
MessageStructure= 'json'
)
def handler(event, context):
"""
The function grabs the number of the latest release
:param event:
:param context:
:return:
"""
responce = requests.get(tf_github_url)
raw_content = responce.content
soup = BeautifulSoup(raw_content)
latest_release = soup.find("div", "release label-latest").find("div", "release-header").find("a").string
# pprint.pprint(latest_release) #debug
# publish it to an SNS topic
message = {"ATTENTION:": "The latest Terraform version is %s" % latest_release}
post_to_SNS(SNS_topic_ARN=sns_topic_arn, msg=message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment