-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "AllowCreateLogGroup", | ||
"Effect": "Allow", | ||
"Action": "logs:CreateLogGroup", | ||
"Resource": "arn:aws:logs:us-east-1:{AWS_ACCOUNT}:*" | ||
}, | ||
{ | ||
"Sid": "AllowPutLogEvents", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
"Resource": [ | ||
"arn:aws:logs:us-east-1:{AWS_ACCOUNT}:log-group:/aws/lambda/{LAMBDA_FUNCTION}:*" | ||
] | ||
}, | ||
{ | ||
"Sid": "AllowGetItemDynamoDBTable", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"dynamodb:GetItem" | ||
], | ||
"Resource": [ | ||
"arn:aws:dynamodb:us-east-1:{AWS_ACCOUNT}:table/{DYNAMODB_TABLE}" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" Return CodeBuild build status information for API integration with | ||
shields.io | ||
""" | ||
|
||
import json | ||
import os | ||
|
||
import boto3 | ||
|
||
|
||
def lambda_handler(event, context): | ||
if event["requestContext"]["http"]["method"] == "GET": | ||
build_project = event["requestContext"]["http"]["path"].split("/")[1] | ||
return { | ||
'statusCode': 200, | ||
'body': get_shields_io_json(build_project) | ||
} | ||
else: | ||
return { | ||
'statusCode': 405 | ||
} | ||
|
||
|
||
def get_shields_io_json(build_project): | ||
dynamodb_client = boto3.client("dynamodb") | ||
|
||
# Get build_status | ||
response = dynamodb_client.get_item( | ||
TableName=os.environ["DYNAMODB_TABLE"], | ||
Key={"build_project": {"S": build_project}} | ||
) | ||
try: | ||
build_status = response["Item"]["build_status"]["S"] | ||
except KeyError: | ||
build_status = None | ||
|
||
# Map build status to message/color | ||
if build_status == "SUCCEEDED": | ||
message = "passing" | ||
color = "success" | ||
elif build_status == "FAILED": | ||
message = "failing" | ||
color = "critical" | ||
else: | ||
message = "no status" | ||
color = "inactive" | ||
|
||
# Return JSON in the format expected by shields.io | ||
# See: https://shields.io/endpoint | ||
return json.dumps({ | ||
"schemaVersion": 1, | ||
"label": build_project, | ||
"message": message, | ||
"color": color | ||
}, indent=4) | ||
|
8 changes: 8 additions & 0 deletions
8
extras/lambda/codebuild-badges-eventbridge/eventbridge-rule-template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"source": ["aws.codebuild"], | ||
"detail-type": ["CodeBuild Build State Change"], | ||
"detail": { | ||
"build-status": ["SUCCEEDED", "FAILED"], | ||
"project-name": ["{PROJECT_1}", "{PROJECT_2}"] | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
extras/lambda/codebuild-badges-eventbridge/iam-role-template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "AllowCreateLogGroup", | ||
"Effect": "Allow", | ||
"Action": "logs:CreateLogGroup", | ||
"Resource": "arn:aws:logs:us-east-1:{AWS_ACCOUNT}:*" | ||
}, | ||
{ | ||
"Sid": "AllowPutLogEvents", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
"Resource": [ | ||
"arn:aws:logs:us-east-1:{AWS_ACCOUNT}:log-group:/aws/lambda/{LAMBDA_FUNCTION}:*" | ||
] | ||
}, | ||
{ | ||
"Sid": "AllowPutItemDynamoDBTable", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"dynamodb:PutItem" | ||
], | ||
"Resource": [ | ||
"arn:aws:dynamodb:us-east-1:{AWS_ACCOUNT}:table/{DYNAMODB_TABLE}" | ||
] | ||
} | ||
] | ||
} |
28 changes: 28 additions & 0 deletions
28
extras/lambda/codebuild-badges-eventbridge/lambda_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" Update build status information from CodeBuild EventBridge events | ||
""" | ||
|
||
import os | ||
|
||
import boto3 | ||
|
||
|
||
def lambda_handler(event, context): | ||
if (event["detail-type"] == "CodeBuild Build State Change" | ||
and event["detail"]["build-status"] in ["SUCCEEDED", "FAILED"]): | ||
set_build_status( | ||
event["detail"]["project-name"], | ||
event["detail"]["build-status"] | ||
) | ||
|
||
|
||
def set_build_status(build_project, build_status): | ||
dynamodb_client = boto3.client("dynamodb") | ||
|
||
dynamodb_client.put_item( | ||
TableName=os.environ["DYNAMODB_TABLE"], | ||
Item={ | ||
"build_project": {"S": build_project}, | ||
"build_status": {"S": build_status} | ||
} | ||
) | ||
|