Intial setup
This commit is contained in:
parent
546fccc0a0
commit
206284e599
37
.github/workflows/ship.yml
vendored
Normal file
37
.github/workflows/ship.yml
vendored
Normal 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 }}
|
19
create_issue/lambda_function.py
Normal file
19
create_issue/lambda_function.py
Normal 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"))
|
2
create_issue/requirements.txt
Normal file
2
create_issue/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
boto3
|
||||||
|
PyGithub
|
41
top.yaml
Normal file
41
top.yaml
Normal 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
|
Reference in New Issue
Block a user