This repository has been archived on 2023-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
github-issue-sns-topic/create_issue/lambda_function.py

27 lines
909 B
Python
Raw Permalink Normal View History

2020-08-13 07:06:25 +02:00
import logging, boto3, os
from github import Github
logger = logging.getLogger()
logger.setLevel(logging.INFO)
2020-11-17 01:19:29 +01:00
2020-08-13 07:06:25 +02:00
def lambda_handler(event, context):
2020-11-17 01:19:29 +01:00
# Secret Client
secretsmanager = boto3.client('secretsmanager')
# Get Secrets
token = secretsmanager.get_secret_value(SecretId=os.environ.get("GITHUB_TOKEN_SECRET")).get("SecretString")
# GitHub client
2020-11-26 06:04:47 +01:00
github = Github(base_url=f"https://{os.environ.get('GITHUB_API_ENDPOINT','api.github.com')}", login_or_token=token)
2020-11-17 01:19:29 +01:00
2020-08-13 07:06:25 +02:00
repo = github.get_repo(os.environ.get("REPOSITORY"))
if not "Records" in event:
raise Exception("Missing key Records in event!")
for record in event["Records"]:
if "Sns" in record:
sns_event = record["Sns"]
2020-11-26 06:07:57 +01:00
repo.create_issue(sns_event["Subject"], body=sns_event["Message"] + "\n\nThis was generated by " + os.environ.get("GENERATED_OWNER", "AWS"))