-
Notifications
You must be signed in to change notification settings - Fork 14
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
nikitadugar
committed
Apr 15, 2020
1 parent
a8a2178
commit aefd895
Showing
10 changed files
with
109 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ Here are some examples of how you can use this module in your inventory structur | |
names = [ | ||
"python_layer" | ||
] | ||
layer_filename = "./../../lambda/packages/Python3-lambda.zip" | ||
layer_filenames = ["./../../lambda/packages/Python3-lambda.zip"] | ||
compatible_runtimes = [ | ||
["python3.8"] | ||
] | ||
|
@@ -172,7 +172,7 @@ Here are some examples of how you can use this module in your inventory structur | |
| iam\_actions | The actions for Iam Role Policy. | list | `<list>` | no | | ||
| kms\_key\_arn | The ARN for the KMS encryption key. | string | `""` | no | | ||
| label\_order | Label order, e.g. `name`,`application`. | list | `<list>` | no | | ||
| layer\_filename | The path to the function's deployment package within the local filesystem. If defined, The s3\_-prefixed options cannot be used. | string | `""` | no | | ||
| layer\_filenames | The path to the function's deployment package within the local filesystem. If defined, The s3\_-prefixed options cannot be used. | list | `<list>` | no | | ||
| layers | List of Lambda Layer Version ARNs \(maximum of 5\) to attach to your Lambda Function. | string | `""` | no | | ||
| license\_infos | License info for your Lambda Layer. See License Info. | list | `<list>` | no | | ||
| managedby | ManagedBy, eg 'CloudDrove' or 'AnmolNagpal'. | string | `"[email protected]"` | no | | ||
|
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
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,12 @@ | ||
#!/bin/bash | ||
export WRKDIR=$(pwd) | ||
export LYR_PDS_DIR="slack" | ||
|
||
#Init Packages Directory | ||
mkdir -p packages/ | ||
|
||
# Building Python-pandas layer | ||
cd ${WRKDIR}/${LYR_PDS_DIR}/ | ||
${WRKDIR}/${LYR_PDS_DIR}/build_layer.sh | ||
zip -r ${WRKDIR}/packages/Python3-slack.zip . | ||
rm -rf ${WRKDIR}/${LYR_PDS_DIR}/python/ |
Empty file.
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,4 @@ | ||
#!/bin/bash | ||
export PKG_DIR="python" | ||
rm -rf ${PKG_DIR} && mkdir -p ${PKG_DIR} && docker run -rm -v $(pwd):/foo lambci/lambda:build-python3.8 | ||
pip install -r requirements.txt --no-deps -t ${PKG_DIR} |
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,5 @@ | ||
urllib5==5.0.0 | ||
certifi==2020.4.5.1 | ||
chardet==3.0.4 | ||
idna==2.9 | ||
requests==2.23.0 |
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,80 @@ | ||
import boto3 | ||
import os | ||
import logging | ||
import json | ||
import requests | ||
import collections | ||
import datetime | ||
import sys | ||
import pprint | ||
|
||
logger = logging.getLogger() | ||
logger.setLevel(logging.INFO) | ||
|
||
ec = boto3.client("ec2") | ||
|
||
SLACK_CHANNEL = os.environ['SLACK_CHANNEL'] | ||
SLACK_WEBHOOK = os.environ['SLACK_WEBHOOK'] | ||
ICON_EMOJI = ':cloudtrail:' | ||
USERNAME = 'CloudTrail Bot' | ||
|
||
def lambda_handler(event, context): | ||
message = json.loads(event["Records"][0]["Sns"]["Message"]) | ||
payload = create_slack_payload({ | ||
'Message': message | ||
}) | ||
post_to_slack(payload) | ||
|
||
def create_slack_payload(json_dict, color='#FF0000', reason='Alarm Event.'): | ||
logger.info('Creating slack payload from the following json: {}'.format(json_dict)) | ||
payload ={ | ||
"attachments": [ | ||
{ | ||
"fallback": reason, | ||
"color": color, | ||
"title": reason, | ||
"fields": [ | ||
{ | ||
"title": "Action", | ||
"value": "Config Rules Notification", | ||
"short": True | ||
}, | ||
{ | ||
"title": "Message", | ||
"value": '```\n{}\n```'.format(json.dumps(json_dict['Message'], indent=4)), | ||
"short": False | ||
} | ||
], | ||
"footer": "CloudDrove", | ||
"footer_icon": "https://clouddrove.com/media/images/favicon.ico", | ||
} | ||
], | ||
'channel': SLACK_CHANNEL, | ||
'username': USERNAME, | ||
'icon_emoji': ICON_EMOJI | ||
} | ||
|
||
return payload | ||
|
||
|
||
def post_to_slack(payload): | ||
logger.info('POST-ing payload: {}'.format(json.dumps(payload,indent=4))) | ||
|
||
try: | ||
req = requests.post(SLACK_WEBHOOK, data=str(payload), timeout=3) | ||
logger.info("Message posted to {} using {}".format(payload['channel'], SLACK_WEBHOOK)) | ||
except requests.exceptions.Timeout as e: | ||
fatal("Server connection failed: {}".format(e)) | ||
except requests.exceptions.RequestException as e: | ||
fatal("Request failed: {}".format(e)) | ||
|
||
if req.status_code != 200: | ||
fatal( | ||
"Non 200 status code: {}\nResponse Headers: {}\nResponse Text: {}".format( | ||
req.status_code, | ||
req.headers, | ||
json.dumps(req.text, indent=4) | ||
), | ||
code=255 | ||
) | ||
|
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