From 8d2ee0f91e32ec0e4536ae71db69b733b16c9602 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Mon, 16 Nov 2020 19:19:29 -0500 Subject: [PATCH] Add token param --- .github/workflows/ship.yml | 2 +- create_issue/lambda_function.py | 12 +++++++++++- top.yaml | 5 ++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ship.yml b/.github/workflows/ship.yml index 40592ec..d371755 100644 --- a/.github/workflows/ship.yml +++ b/.github/workflows/ship.yml @@ -4,7 +4,7 @@ name: Build & Ship on: push: branches: - - master + - main jobs: deploy: diff --git a/create_issue/lambda_function.py b/create_issue/lambda_function.py index cc69bc0..5d6f69e 100644 --- a/create_issue/lambda_function.py +++ b/create_issue/lambda_function.py @@ -4,10 +4,20 @@ from github import Github logger = logging.getLogger() logger.setLevel(logging.INFO) -github = Github("") + + def lambda_handler(event, context): + # Secret Client + secretsmanager = boto3.client('secretsmanager') + + # Get Secrets + token = secretsmanager.get_secret_value(SecretId=os.environ.get("GITHUB_TOKEN_SECRET")).get("SecretString") + + # GitHub client + github = Github(token) + repo = github.get_repo(os.environ.get("REPOSITORY")) if not "Records" in event: diff --git a/top.yaml b/top.yaml index f03b453..9d2bf38 100644 --- a/top.yaml +++ b/top.yaml @@ -7,6 +7,8 @@ Parameters: Type: String GenerateOwnerName: Type: String + GitHubTokenSecret: + Type: String Resources: SnsTopic: @@ -31,6 +33,7 @@ Resources: Variables: GENERATED_OWNER: !Ref GenerateOwnerName REPOSITORY: !Ref GithubRepository + GITHUB_TOKEN_SECRET: !Ref GitHubTokenSecret SnsLambdaPermission: Type: AWS::Lambda::Permission @@ -38,4 +41,4 @@ Resources: Action: lambda:InvokeFunction Principal: sns.amazonaws.com SourceArn: !Ref SnsTopic - FunctionName: !GetAtt AlertHandler.Arn + FunctionName: !GetAtt CreateIssueLambda.Arn