Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit da597a9

Browse files
authored
Merge pull request #764 from aws-solutions/release/v5.1.8
Release v5.1.8
2 parents 83a7393 + 42290f1 commit da597a9

File tree

20 files changed

+243
-31
lines changed

20 files changed

+243
-31
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [5.1.8] - 2024-08-26
9+
10+
### Changed
11+
12+
- Upgrading NLTK version
13+
814
## [5.1.7] - 2024-06-11
915

1016
### Changed

SECURITY.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Reporting Security Issues
2+
3+
We take all security reports seriously.
4+
When we receive such reports,
5+
we will investigate and subsequently address
6+
any potential vulnerabilities as quickly as possible.
7+
If you discover a potential security issue in this project,
8+
please notify AWS/Amazon Security via our
9+
[vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/)
10+
or directly via email to [AWS Security](mailto:aws-security@amazon.com).
11+
Please do *not* create a public GitHub issue in this project.

deployment/build-s3-dist.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#
2626
###############################################################################
2727

28+
source "$(dirname "${BASH_SOURCE[0]}")/nltk_download_functions.sh"
29+
2830
usage() {
2931
msg "$1"
3032
cat <<EOF
@@ -63,6 +65,8 @@ cleanup() {
6365
echo "------------------------------------------------------------------------------"
6466
fi
6567
[ -n "$VENV" ] && [ -d "$VENV" ] && rm -rf "$VENV"
68+
69+
cleanup_punkt "$source_dir"
6670
}
6771

6872
msg() {
@@ -228,7 +232,7 @@ pip3 install wheel
228232
# See the following issues for more details:
229233
# - https://github.com/aws/aws-cdk/issues/26300
230234
# - https://github.com/python-jsonschema/jsonschema/issues/1117
231-
pip3 install --quiet boto3 chalice==1.31.0 docopt pyyaml jsonschema==4.17.3 aws_xray_sdk
235+
pip3 install --quiet boto3 chalice==1.31.2 docopt pyyaml jsonschema==4.17.3 aws_xray_sdk
232236
export PYTHONPATH="$PYTHONPATH:$source_dir/lib/MediaInsightsEngineLambdaHelper/"
233237
if [ $? -ne 0 ]; then
234238
echo "ERROR: Failed to install required Python libraries."
@@ -257,6 +261,7 @@ cd "$source_dir"/lib/MediaInsightsEngineLambdaHelper || exit 1
257261
rm -rf build
258262
rm -rf dist
259263
rm -rf Media_Insights_Engine_Lambda_Helper.egg-info
264+
python3 -m pip install -r requirements.txt
260265
python3 setup.py bdist_wheel > /dev/null
261266
echo -n "Created: "
262267
find "$source_dir"/lib/MediaInsightsEngineLambdaHelper/dist/
@@ -297,6 +302,7 @@ else
297302
cp -R "$source_dir"/lib/MediaInsightsEngineLambdaHelper .
298303
cd MediaInsightsEngineLambdaHelper/ || exit 1
299304
echo "Building Media Insights on AWS Lambda Helper python library"
305+
python3 -m pip install -r requirements.txt
300306
python3 setup.py bdist_wheel > /dev/null
301307
cp dist/*.whl ../
302308
cp dist/*.whl "$source_dir"/lib/MediaInsightsEngineLambdaHelper/dist/
@@ -452,6 +458,7 @@ rm -rf ./dist ./package
452458
# ------------------------------------------------------------------------------"
453459

454460
echo "Building Translate function"
461+
download_punkt "$source_dir"
455462
cd "$source_dir/operators/translate" || exit 1
456463
[ -e dist ] && rm -rf dist
457464
mkdir -p dist
@@ -466,12 +473,16 @@ touch ./setup.cfg
466473
echo "[install]" > ./setup.cfg
467474
echo "prefix= " >> ./setup.cfg
468475
pip3 install --quiet -r ../requirements.txt --target .
476+
# copy downloaded nltk_data pickles to the package
477+
cp -r ../nltk_data nltk_data
478+
469479
if ! [ -d ../dist/start_translate.zip ]; then
470480
zip -q -r9 ../dist/start_translate.zip .
471481

472482
elif [ -d ../dist/start_translate.zip ]; then
473483
echo "Package already present"
474484
fi
485+
475486
popd || exit 1
476487
zip -q -g ./dist/start_translate.zip ./start_translate.py
477488
cp "./dist/start_translate.zip" "$regional_dist_dir/start_translate.zip"

deployment/lambda_layer_factory/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM amazonlinux
1+
FROM public.ecr.aws/amazonlinux/amazonlinux:2023.5.20240819.0
22

33
WORKDIR /
44
RUN yum update -y
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
3+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
###############################################################################
7+
# PURPOSE: This script provides utility functions to download and verify the
8+
# hash of NLTK pickles.
9+
#
10+
# PRELIMINARY:
11+
# Sourced from within another script.
12+
#
13+
# USAGE:
14+
# source "${path}/nltk_download_functions.sh"
15+
#
16+
# Where ${path} is the directory containing this script. If the calling
17+
# script is in the same directory, use "$(dirname "${BASH_SOURCE[0]}")".
18+
# Example: source "$(dirname "${BASH_SOURCE[0]}")/nltk_download_functions.sh"
19+
#
20+
###############################################################################
21+
22+
verify_hash() {
23+
local file_path="$1"
24+
local expected_hash="$2"
25+
local actual_hash=$(sha256sum "$file_path" | awk '{print $1}')
26+
27+
if [ "$actual_hash" != "$expected_hash" ]; then
28+
echo "Hash mismatch found for $file_path"
29+
echo "Expected: $expected_hash"
30+
echo "Found: $actual_hash"
31+
return 1
32+
else
33+
return 0
34+
fi
35+
}
36+
37+
function download_punkt() {
38+
cleanup_punkt "${1}"
39+
echo "Starting download of punkt zip file..."
40+
41+
local -r source_dir="${1}"
42+
local -r zip_url="https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/tokenizers/punkt.zip"
43+
local -r zip_file="punkt.zip"
44+
# this hash was verified to be working, it may need to be updated if nltk ever updates punkt pickles
45+
local -r expected_hash="51c3078994aeaf650bfc8e028be4fb42b4a0d177d41c012b6a983979653660ec"
46+
local temp_dir
47+
48+
# Download the punkt zip file
49+
if ! curl -sSL "$zip_url" -o "$zip_file"; then
50+
echo "Error: Failed to download the zip file."
51+
return 1
52+
fi
53+
54+
echo "Verifying hash against the last known valid hash..."
55+
56+
# Verify the hash
57+
if ! verify_hash "$zip_file" "$expected_hash"; then
58+
echo "Hash verification failed. Please check if the new punkt file is valid. Exiting."
59+
rm -f "$zip_file"
60+
return 1
61+
fi
62+
63+
# Create a temporary directory for extraction
64+
temp_dir=$(mktemp -d)
65+
if [[ ! -d "$temp_dir" ]]; then
66+
echo "Error: Failed to create a temporary directory."
67+
rm -f "$zip_file"
68+
return 1
69+
fi
70+
71+
# Extract the zip file into the temporary directory
72+
if ! unzip -q "$zip_file" -d "$temp_dir"; then
73+
echo "Error: Failed to unzip the file."
74+
rm -rf "$temp_dir"
75+
rm -f "$zip_file"
76+
return 1
77+
fi
78+
79+
# Create the destination directory and copy files
80+
# interacting directly with the app under /operators/translate for now until more apps
81+
# within the solution need punkt pickles
82+
local -r dest_dir="$source_dir/operators/translate/nltk_data/tokenizers/punkt"
83+
mkdir -p "$dest_dir"
84+
cp -r "$temp_dir/punkt/PY3/"* "$dest_dir/"
85+
86+
# Clean up temporary files
87+
rm -rf "$temp_dir"
88+
rm -f "$zip_file"
89+
90+
echo "Punkt zip file downloaded and extracted successfully."
91+
}
92+
93+
function cleanup_punkt() {
94+
local -r source_dir="${1}"
95+
local -r target_dir="$source_dir/operators/translate/nltk_data"
96+
97+
echo "Starting cleanup process for punkt data..."
98+
99+
# Check if the target directory exists
100+
if [[ -d "$target_dir" ]]; then
101+
# Attempt to remove the directory
102+
if rm -rf "$target_dir"; then
103+
echo "Successfully removed the nltk_data directory at $target_dir."
104+
else
105+
echo "Error: Failed to remove the nltk_data directory at $target_dir."
106+
return 1
107+
fi
108+
else
109+
echo "The directory $target_dir does not exist. No cleanup necessary."
110+
fi
111+
112+
echo "Cleanup process completed."
113+
return 0
114+
}

deployment/run-unit-tests.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# cd deployment
55
# ./run-unit-tests.sh
66

7+
source "$(dirname "${BASH_SOURCE[0]}")/nltk_download_functions.sh"
8+
79
# Run unit tests
810
echo "Running unit tests"
911

@@ -12,9 +14,24 @@ echo "Installing Dependencies And Testing CDK"
1214
echo "------------------------------------------------------------------------------"
1315
chmod +x ../source/cdk/run-tests.sh && ../source/cdk/run-tests.sh || exit $?
1416

15-
echo "cd ../test/unit"
16-
cd ../test/unit
17+
18+
build_dir="$(dirname "${BASH_SOURCE[0]}")"
19+
source_dir="$build_dir/../source"
20+
21+
download_punkt "$source_dir"
22+
23+
echo "pushd ../test/unit"
24+
pushd ../test/unit
1725
echo "------------------------------------------------------------------------------"
1826
echo "Installing Dependencies And Testing Modules"
1927
echo "------------------------------------------------------------------------------"
2028
./run_unit.sh
29+
30+
if [ $? -ne 0 ]; then
31+
echo "ERROR: Unit test script failed"
32+
exit 1
33+
fi
34+
35+
echo "popd"
36+
popd
37+
cleanup_punkt "$source_dir"

solution-manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
id: SO0163
22
name: media-insights-on-aws
3-
version: 5.1.7
3+
version: 5.1.8
44
cloudformation_templates:
55
- template: media-insights-on-aws-stack.template
66
main_template: true

source/cdk/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/cdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "media-insights-on-aws",
3-
"version": "5.1.7",
3+
"version": "5.1.8",
44
"description": "Synthesize templates for Media Insights on AWS using AWS Cloud Development Kit (CDK).",
55
"license": "Apache-2.0",
66
"private": true,

source/cdk/test/__snapshots__/media-insights-stack.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,7 @@ exports[`Snapshot media-insights root stack test 1`] = `
20772077
"CodeKeyPrefix",
20782078
],
20792079
},
2080-
"media_insights_on_aws_lambda_layer_python3.10-v5.1.7.zip",
2080+
"media_insights_on_aws_lambda_layer_python3.10-v5.1.8.zip",
20812081
],
20822082
],
20832083
},
@@ -2124,7 +2124,7 @@ exports[`Snapshot media-insights root stack test 1`] = `
21242124
"CodeKeyPrefix",
21252125
],
21262126
},
2127-
"media_insights_on_aws_lambda_layer_python3.11-v5.1.7.zip",
2127+
"media_insights_on_aws_lambda_layer_python3.11-v5.1.8.zip",
21282128
],
21292129
],
21302130
},
@@ -2171,7 +2171,7 @@ exports[`Snapshot media-insights root stack test 1`] = `
21712171
"CodeKeyPrefix",
21722172
],
21732173
},
2174-
"media_insights_on_aws_lambda_layer_python3.9-v5.1.7.zip",
2174+
"media_insights_on_aws_lambda_layer_python3.9-v5.1.8.zip",
21752175
],
21762176
],
21772177
},

0 commit comments

Comments
 (0)