Intial setup

This commit is contained in:
Layla 2020-08-13 01:06:25 -04:00
parent 546fccc0a0
commit 206284e599
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31
4 changed files with 99 additions and 0 deletions

37
.github/workflows/ship.yml vendored Normal file
View File

@ -0,0 +1,37 @@
name: Build & Ship
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v1
- name: Build Lambdas
run: |
file="create_issue"
echo "Building: $file"
cd $file
echo "Installing requirements..."
pip install -q -r requirements.txt -t .
echo "Zipping..."
zip -qq -r ../$file.zip .
cd ..
echo "Cleaning up..."
rm -rf $file
- name: Ship to S3
uses: jakejarvis/s3-sync-action@master
with:
args: --follow-symlinks --delete
env:
SOURCE_DIR: "./"
AWS_REGION: "us-east-1"
DEST_DIR: github-issues
AWS_S3_BUCKET: sumu-stacks
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

View File

@ -0,0 +1,19 @@
import logging, boto3, os
from github import Github
logger = logging.getLogger()
logger.setLevel(logging.INFO)
github = Github("")
def lambda_handler(event, context):
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"]
repo.create_issue(sns_event["Subject"], body=sns_event["Message"] + "\nThis was generated by " + os.environ.get("GENERATED_OWNER", "AWS"))

View File

@ -0,0 +1,2 @@
boto3
PyGithub

41
top.yaml Normal file
View File

@ -0,0 +1,41 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: SNS Topic to create GitHub Issues
Parameters:
TopicName:
Type: String
GithubRepository:
Type: String
GenerateOwnerName:
Type: String
Resources:
SnsTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: !Ref TopicName
CreateIssueLambda:
Type: AWS::Lambda::Function
Properties:
Handler: lambda_function.lambda_handler
Runtime: python3.8
Code:
S3Bucket: "sumu-stacks"
S3Key: !Sub "github-issues/create_issue.zip"
FunctionName: "Github-CreateIssue"
Description: Lambda that creates a issue in Github
MemorySize: 128
Timeout: 10
#Role: !GetAtt AlertExecutionerRole.Arn
Environment:
Variables:
GENERATED_OWNER: !Ref GenerateOwnerName
REPOSITORY: !Ref GithubRepository
SnsLambdaPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
Principal: sns.amazonaws.com
SourceArn: !Ref SnsTopic
FunctionName: !GetAtt AlertHandler.Arn