Skip to content

Commit c8378f0

Browse files
committed
chore!: Deprecate python3.6 runtime
1 parent 2218bbf commit c8378f0

20 files changed

+102
-58
lines changed
File renamed without changes.

.github/workflows/check-deployments.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,20 @@ jobs:
5252
- run: |
5353
NAME=${{ matrix.name }}
5454
RUNTIME=${{ matrix.runtime }}
55+
DEPLOYMENT=deployment-$NAME-$RUNTIME.zip
5556
#
5657
echo NAME=$NAME RUNTIME=$RUNTIME
5758
#
58-
cp $NAME-$RUNTIME.zip $NAME-$RUNTIME.zip_original
59+
cp $DEPLOYMENT ${DEPLOYMENT}_original
5960
cd $NAME
60-
zip -r ../$NAME-$RUNTIME.zip .
61+
zip -r ../$DEPLOYMENT .
6162
cd ..
6263
#
6364
# Compare length and names of files in Zip.
6465
# Building in Docker doesn't work, some files are still different.
65-
[[ -f $NAME-$RUNTIME.zip ]] || { echo "Deployment file not found."; exit 1; }
66+
[[ -f $DEPLOYMENT ]] || { echo "Deployment file not found."; exit 1; }
6667
diff \
67-
<(unzip -vqq $NAME-$RUNTIME.zip | awk '{$2=""; $3=""; $4=""; $5=""; $6=""; print}' | sort -k3 -f) \
68-
<(unzip -vqq $NAME-$RUNTIME.zip_original | awk '{$2=""; $3=""; $4=""; $5=""; $6=""; print}' | sort -k3 -f)
68+
<(unzip -vqq $DEPLOYMENT | awk '{$2=""; $3=""; $4=""; $5=""; $6=""; print}' | sort -k3 -f) \
69+
<(unzip -vqq ${DEPLOYMENT}_original | awk '{$2=""; $3=""; $4=""; $5=""; $6=""; print}' | sort -k3 -f)
6970
FILES_CHANGED=$?
7071
echo FILES_CHANGED=$FILES_CHANGED

.github/workflows/pre-commit-and-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
if: failure()
6060
run: |
6161
LOG_FILE=~/.cache/pre-commit/pre-commit.log
62-
[ -f $LOG_FILE ] || cat $LOG_FILE
62+
[ -f $LOG_FILE ] && cat $LOG_FILE
6363
6464
#--------------------------------------------------------------
6565
# TESTS

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ jobs:
6565
[[ -z "$TAG_NAME" ]] && { echo "TAG_NAME is empty" ; exit 1; }
6666
#
6767
gh config set prompt disabled
68-
gh release upload $TAG_NAME *.zip
68+
gh release upload $TAG_NAME deployment-*.zip

.tfsec-config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414

1515
---
1616
exclude:
17-
# Add IDs of checks to ignore them
18-
# - aws-sns-topic-encryption-use-cmk
17+
# Add IDs of checks to ignore them
18+
# - aws-sns-topic-encryption-use-cmk
19+
# Without full tracing enabled it is difficult to trace the flow of logs
20+
- aws-lambda-enable-tracing

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Full contributing [guidelines are covered here](.github/contributing.md).
5050
| <a name="input_included_accounts"></a> [included\_accounts](#input\_included\_accounts) | List of accounts that be scanned to manual actions. If empty will scan all accounts. | `list(string)` | `[]` | no |
5151
| <a name="input_included_users"></a> [included\_users](#input\_included\_users) | List of emails that be scanned to manual actions. If empty will scan all emails. | `list(string)` | `[]` | no |
5252
| <a name="input_lambda_memory_size"></a> [lambda\_memory\_size](#input\_lambda\_memory\_size) | The amount of memory for Lambda to use | `number` | `"128"` | no |
53-
| <a name="input_lambda_runtime"></a> [lambda\_runtime](#input\_lambda\_runtime) | The lambda runtime to use | `string` | `"python3.8"` | no |
53+
| <a name="input_lambda_runtime"></a> [lambda\_runtime](#input\_lambda\_runtime) | The lambda runtime to use. One of: `["python3.9", "python3.8", "python3.7"]` | `string` | `"python3.8"` | no |
5454
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | Number of days to keep CloudWatch logs | `number` | `14` | no |
5555
| <a name="input_message_format"></a> [message\_format](#input\_message\_format) | Where do you want to send this message? slack or msteams | `string` | `"slack"` | no |
5656
| <a name="input_naming_prefix"></a> [naming\_prefix](#input\_naming\_prefix) | Resources will be prefixed with this | `string` | `"clickops-notifier"` | no |

build_one.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ NAME=$1
1111
LAMBDA_RUNTIME=$2
1212
echo "*** NAME=$NAME LAMBDA_RUNTIME=$LAMBDA_RUNTIME "
1313

14-
DEPLOYMENT_FILE=$NAME-$LAMBDA_RUNTIME.zip
14+
DEPLOYMENT_FILE=deployment-$NAME-$LAMBDA_RUNTIME.zip
15+
16+
[[ -d $DEPLOYMENT_FILE ]] && rm -f $DEPLOYMENT_FILE
1517

1618
cd $NAME
1719

1820
[[ -d .package ]] && rm -rf .package
19-
[[ -d $DEPLOYMENT_FILE ]] && rm -f $DEPLOYMENT_FILE
2021

2122
# Build requirements in Lambda environment
22-
docker run -v "$PWD":/var/task "public.ecr.aws/sam/build-$LAMBDA_RUNTIME" /bin/sh -c "pip install -r requirements.txt -t .package; exit"
23+
docker run --platform linux/amd64 -v "$PWD":/var/task "public.ecr.aws/sam/build-$LAMBDA_RUNTIME" /bin/sh -c "pip install -r requirements.txt -t .package; exit"
2324

2425
# Create deployment package
2526
echo "*** Adding requirements to $DEPLOYMENT_FILE"

build_targets.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{
22
"include": [
3-
{
4-
"name": "clickopsnotifier",
5-
"runtime": "python3.6"
6-
},
73
{
84
"name": "clickopsnotifier",
95
"runtime": "python3.7"

clickopsnotifier-python3.6.zip

-811 KB
Binary file not shown.

clickopsnotifier/app.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,31 @@
77
import base64
88
import os
99
from typing import Tuple
10+
import logging
1011

1112
from clickops import ClickOpsEventChecker, CloudTrailEvent
1213
from messenger import Messenger
1314
from delivery_stream import DeliveryStream
1415

15-
s3 = boto3.client("s3")
16-
ssm = boto3.client("ssm")
16+
logger = logging.getLogger("clickopsnotifier")
17+
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
18+
logger.setLevel(LOG_LEVEL)
1719

18-
WEBHOOK_PARAMETER = os.environ["WEBHOOK_PARAMETER"]
19-
EXCLUDED_ACCOUNTS = json.loads(os.environ["EXCLUDED_ACCOUNTS"])
20-
INCLUDED_ACCOUNTS = json.loads(os.environ["INCLUDED_ACCOUNTS"])
21-
EXCLUDED_USERS = json.loads(os.environ["EXCLUDED_USERS"])
22-
INCLUDED_USERS = json.loads(os.environ["INCLUDED_USERS"])
23-
EXCLUDED_SCOPED_ACTIONS = json.loads(os.environ["EXCLUDED_SCOPED_ACTIONS"])
24-
MESSAGE_FORMAT = os.environ["MESSAGE_FORMAT"]
25-
LOG_LEVEL = os.environ["LOG_LEVEL"]
20+
WEBHOOK_PARAMETER = os.environ.get("WEBHOOK_PARAMETER", "")
21+
EXCLUDED_ACCOUNTS = json.loads(os.environ.get("EXCLUDED_ACCOUNTS", "[]"))
22+
INCLUDED_ACCOUNTS = json.loads(os.environ.get("INCLUDED_ACCOUNTS", "[]"))
23+
EXCLUDED_USERS = json.loads(os.environ.get("EXCLUDED_USERS", "[]"))
24+
INCLUDED_USERS = json.loads(os.environ.get("INCLUDED_USERS", "[]"))
25+
EXCLUDED_SCOPED_ACTIONS = json.loads(os.environ.get("EXCLUDED_SCOPED_ACTIONS", "[]"))
26+
MESSAGE_FORMAT = os.environ.get("MESSAGE_FORMAT", "slack")
2627

2728
FIREHOSE_DELIVERY_STREAM_NAME = os.environ.get("FIREHOSE_DELIVERY_STREAM_NAME")
2829
if FIREHOSE_DELIVERY_STREAM_NAME == "__NONE__":
2930
FIREHOSE_DELIVERY_STREAM_NAME = None
3031

32+
s3 = boto3.client("s3")
33+
ssm = boto3.client("ssm")
34+
3135
WEBHOOK_URL = None
3236

3337

@@ -91,6 +95,9 @@ def handler_organizational(event, context) -> None: # noqa: C901
9195
:return: None
9296
"""
9397

98+
if event is None:
99+
raise KeyError("event is None")
100+
94101
webhook_url = get_webhook()
95102

96103
messenger = Messenger(format=MESSAGE_FORMAT, webhook=webhook_url)
@@ -104,7 +111,6 @@ def handler_organizational(event, context) -> None: # noqa: C901
104111
records = s3_events.get("Records", [])
105112

106113
for record in records:
107-
108114
# Get the object from the event and show its content type
109115
bucket = record["s3"]["bucket"]["name"]
110116
key = urllib.parse.unquote_plus(
@@ -127,7 +133,6 @@ def handler_organizational(event, context) -> None: # noqa: C901
127133
event_json = json.load(fh)
128134

129135
for event in event_json["Records"]:
130-
131136
event_origin = f"{bucket}/{key}"
132137

133138
success = success and __handle_event(
@@ -146,6 +151,8 @@ def handler_organizational(event, context) -> None: # noqa: C901
146151

147152

148153
def handler_standalone(event, context) -> None:
154+
if event is None:
155+
raise KeyError("event is None")
149156

150157
webhook_url = get_webhook()
151158

@@ -161,7 +168,6 @@ def handler_standalone(event, context) -> None:
161168

162169
success = True
163170
for e in event_json["logEvents"]:
164-
165171
event_origin = (
166172
event_json["logGroup"]
167173
+ ":"

0 commit comments

Comments
 (0)