Skip to content

Commit

Permalink
Merge from aws/aws-sam-cli/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-sam-cli-bot authored Nov 29, 2022
2 parents 6f7dc0b + b202c29 commit 58a3e3e
Show file tree
Hide file tree
Showing 19 changed files with 1,356 additions and 1,499 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
AWS SAM CLI
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copyright 2018-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2,567 changes: 1,094 additions & 1,473 deletions installer/assets/THIRD-PARTY-LICENSES

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion installer/assets/install
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set -eu

usage() {
cat 1>&2 <<EOF
Installs the AWS SAM CLI Linux executable package
Installs the AWS SAM CLI executable package
USAGE:
install [FLAGS] [OPTIONS]
FLAGS:
Expand Down
4 changes: 3 additions & 1 deletion installer/pyinstaller/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ if [ "$is_nightly" = "true" ]; then
fi
echo "samcli.spec content is:"
cat installer/pyinstaller/samcli.spec
../venv/bin/python -m PyInstaller -D --clean installer/pyinstaller/samcli.spec
# --onedir/--onefile options not allowed when spec file provided for
# updated pyinstaller version.
../venv/bin/python -m PyInstaller --clean installer/pyinstaller/samcli.spec


mkdir pyinstaller-output
Expand Down
152 changes: 152 additions & 0 deletions installer/pyinstaller/build-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/bin/sh
set -eu

binary_zip_filename=${1:-}
python_library_zip_filename=${2:-}
python_version=${3:-}
build_binary_name=${4:-}
build_folder=${5:-}
openssl_version=${6:-}
mac_arch="$(uname -m)"
openssl_config_arch=""

# Set architecture to install openssl
if [ "$mac_arch" = "arm64" ]; then
openssl_config_arch="darwin64-arm64-cc"
export PATH=/usr/local/bin:"$PATH"
elif [ "$mac_arch" = "x86_64" ]; then
openssl_config_arch="darwin64-x86_64-cc"
else
echo "Invalid architecture found"
exit 1
fi

if [ "$python_library_zip_filename" = "" ]; then
python_library_zip_filename="python-libraries.zip";
fi

if [ "$openssl_version" = "" ]; then
openssl_version="1.1.1o";
fi

if [ "$python_version" = "" ]; then
python_version="3.8.13";
fi

if ! [ "$build_binary_name" = "" ]; then
echo "Building native installer with nightly/beta build"
is_nightly="true"
else
echo "Building native installer with normal build"
is_nightly="false"
fi

echo "Making Folders"
mkdir -p .build/src
mkdir -p .build/output/aws-sam-cli-src
mkdir -p .build/output/python-libraries
mkdir -p .build/output/pyinstaller-output
cd .build

# Installing Openssl to allow pip configured in the TLS/SSL location to install python libraries
echo "Installing Openssl"
curl -LO https://www.openssl.org/source/openssl-"${openssl_version}".tar.gz
tar -xzf openssl-"${openssl_version}".tar.gz
cd openssl-"$openssl_version"
# Openssl configure https://wiki.openssl.org/index.php/Compilation_and_Installation
./Configure --prefix=/usr/local --openssldir=/usr/local/openssl no-ssl3 no-ssl3-method no-zlib ${openssl_config_arch} enable-ec_nistp_64_gcc_128

make
sudo make install
cd ..

# Copying aws-sam-cli source code
echo "Copying Source"
cp -r ../[!.]* ./src
cp -r ./src/* ./output/aws-sam-cli-src

echo "Removing CI Scripts"
rm -vf ./output/aws-sam-cli-src/appveyor*.yml

echo "Installing Python"
curl "https://www.python.org/ftp/python/${python_version}/Python-${python_version}.tgz" --output python.tgz
tar -xzf python.tgz
cd Python-"$python_version"
./configure --enable-shared
make -j8
sudo make install
cd ..

echo "Installing Python Libraries"
/usr/local/bin/python3.8 -m venv venv
./venv/bin/pip install --upgrade pip
./venv/bin/pip install -r src/requirements/reproducible-linux.txt

echo "Copying All Python Libraries"
cp -r ./venv/lib/python*/site-packages/* ./output/python-libraries

echo "Installing PyInstaller"
./venv/bin/pip install -r src/requirements/pyinstaller-build.txt

# Building the binary using pyinstaller
echo "Building Binary"
cd src
if [ "$is_nightly" = "true" ]; then
# If nightly build, replace the exe_name in spec file with build_binary_name
echo "Updating samcli-mac.spec with nightly/beta build"
sed -i.bak "s/'sam'/'$build_binary_name'/g" installer/pyinstaller/samcli-mac.spec
rm installer/pyinstaller/samcli-mac.spec.bak
fi
echo "samcli-mac.spec content is:"
cat installer/pyinstaller/samcli-mac.spec
# Note: onefile/onedir options are not valid when spec file is used on mac
../venv/bin/python -m PyInstaller --clean installer/pyinstaller/samcli-mac.spec

# Organizing the pyinstaller-output folder
mkdir pyinstaller-output
dist_folder="sam"
if [ "$is_nightly" = "true" ]; then
echo "using dist_folder with nightly/beta build"
dist_folder=$build_binary_name
fi
echo "dist_folder=$dist_folder"
mv "dist/$dist_folder" pyinstaller-output/dist
cp installer/assets/* pyinstaller-output
chmod 755 pyinstaller-output/install
if [ "$is_nightly" = "true" ]; then
echo "Updating install script with nightly/beta build"
# If nightly build, replace the build folder and build_binary_name in the install script
sed -i.bak "s/\/usr\/local\/aws-sam-cli/\/usr\/local\/$build_folder/g" pyinstaller-output/install
sed -i.bak 's/EXE_NAME=\"sam\"/EXE_NAME=\"'"$build_binary_name"'\"/g' pyinstaller-output/install
rm pyinstaller-output/install.bak
fi
echo "install script content is:"
cat pyinstaller-output/install
echo "Copying Binary"
cd ..
cp -r src/pyinstaller-output/* output/pyinstaller-output

echo "Packaging Binary"
cd output
cd pyinstaller-output
cd dist
cd ..
zip -r ../"$binary_zip_filename" ./*
cd ..
zip -r "$binary_zip_filename" aws-sam-cli-src

# Remove unwanted files and zip the python libraries
echo "Packaging Python Libraries"
cd python-libraries
rm -rf ./*.dist-info
rm -rf ./*.egg-info
rm -rf ./__pycache__
rm -rf ./pip
rm -rf ./easy_install.py
rm -rf ./pkg_resources
rm -rf ./setuptools

rm -rf ./*.so
zip -r ../"$python_library_zip_filename" ./*
cd ..
zip -r "$python_library_zip_filename" aws-sam-cli-src
2 changes: 2 additions & 0 deletions installer/pyinstaller/hidden_imports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from samcli.cli.command import _SAM_CLI_COMMAND_PACKAGES

SAM_CLI_HIDDEN_IMPORTS = _SAM_CLI_COMMAND_PACKAGES + [
# terraform hook
"samcli.hook_packages.terraform",
"cookiecutter.extensions",
"jinja2_time",
"text_unidecode",
Expand Down
29 changes: 29 additions & 0 deletions installer/pyinstaller/samcli-mac.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- mode: python -*-
block_cipher = None
exe_name = 'sam'
analysis = Analysis(['../../samcli/__main__.py'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=['./installer/pyinstaller'],
runtime_hooks=[],
excludes=[],
cipher=block_cipher)
pyz = PYZ(analysis.pure, analysis.zipped_data, cipher=block_cipher)
exe = EXE(pyz,
analysis.scripts,
[],
exclude_binaries=True,
name=exe_name,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
analysis.binaries,
analysis.zipfiles,
analysis.datas,
strip=False,
upx=True,
name='sam')
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ boto3>=1.19.5,==1.*
jmespath~=0.10.0
PyYAML~=5.3
cookiecutter~=2.1.1
aws-sam-translator==1.54.0
aws-sam-translator==1.55.0
#docker minor version updates can include breaking changes. Auto update micro version only.
docker~=4.2.0
dateparser~=1.0
requests==2.25.1
serverlessrepo==0.1.10
aws_lambda_builders==1.23.0
aws_lambda_builders==1.23.1
tomlkit==0.7.2
watchdog==2.1.2
pyopenssl==22.0.0
Expand Down
2 changes: 1 addition & 1 deletion requirements/pyinstaller-build.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Executable binary builder requirements
setuptools==47.3.2
pyinstaller==4.2
pyinstaller==5.3
14 changes: 7 additions & 7 deletions requirements/reproducible-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ attrs==20.3.0 \
--hash=sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6 \
--hash=sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700
# via jsonschema
aws-lambda-builders==1.23.0 \
--hash=sha256:36fb732665aac617578a344116f85d061588421b854038b163ba1a380f5ed0f9 \
--hash=sha256:f0a857d68249c7cbeb2569c6acd15fea0956b3f64f6053bf8b33e165fae5d85a
aws-lambda-builders==1.23.1 \
--hash=sha256:4db4133decf149c5b2daa0959db0f6e5563a9763beac0e25005a90c2ce7abe48 \
--hash=sha256:dda6f7e04bc77120c206ef5269a0c17bbcecacf065865248d31c1c80f325a343
# via aws-sam-cli (setup.py)
aws-sam-translator==1.54.0 \
--hash=sha256:10d6771ebbe9107a0ddb756ccffd68ba81d885ef2eace80358a098566e6abaf1 \
--hash=sha256:1bb4abb197e6de3f935425e65f67d14f47eb620d984e9de963b666cc9deb66e4 \
--hash=sha256:a3ae79f1f2d430f5ade4d245165d5612414233f540b471d170f1aab95c3713a6
aws-sam-translator==1.55.0 \
--hash=sha256:08e182e76d6fabc13ce2f38b8a3932b3131407c6ad29ec2849ef3d9a41576b94 \
--hash=sha256:93dc74614ab291c86be681e025679d08f4fa685ed6b55d410f62f2f235012205 \
--hash=sha256:e86a67b87329a0de7d531d33257d1a448d0d6ecd84aee058d084957f28a8e4b1
# via aws-sam-cli (setup.py)
backports-zoneinfo==0.2.1 \
--hash=sha256:17746bd546106fa389c51dbea67c8b7c8f0d14b5526a579ca6ccf5ed72c526cf \
Expand Down
2 changes: 1 addition & 1 deletion samcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
SAM CLI version
"""

__version__ = "1.65.0"
__version__ = "1.66.0"
5 changes: 3 additions & 2 deletions samcli/commands/local/lib/local_api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ def start(self):
LOG.info(
"You can now browse to the above endpoints to invoke your functions. "
"You do not need to restart/reload SAM CLI while working on your functions, "
"changes will be reflected instantly/automatically. You only need to restart "
"SAM CLI if you update your AWS SAM template"
"changes will be reflected instantly/automatically. If you used sam build before "
"running local commands, you will need to re-run sam build for the changes "
"to be picked up. You only need to restart SAM CLI if you update your AWS SAM template"
)

service.run()
Expand Down
4 changes: 4 additions & 0 deletions samcli/hook_packages/terraform/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Expose top level prepare hook
"""
from .main import prepare
2 changes: 1 addition & 1 deletion samcli/runtime_config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"app_template_repo_commit": "6c6b6650d194fe70a289c9829a3ce0f825541954"
"app_template_repo_commit": "af09b91b9914b9c8faf248888bde9b7cfdc45937"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%YAML 1.1
---
Parameters:
SnapStartParam:
Type: String
Default: None

Resources:
SnapStartFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
SnapStart:
ApplyOn: PublishedVersions

SnapStartParameterFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
SnapStart:
ApplyOn: !Ref SnapStartParam

SnapStartFunctionWithAlias:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
AutoPublishAlias: live
SnapStart:
ApplyOn: PublishedVersions
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Globals:
ReservedConcurrentExecutions: 50
Architectures:
- x86_64
SnapStart:
ApplyOn: PublishedVersions
EphemeralStorage:
Size: 1024

Expand Down Expand Up @@ -54,4 +56,6 @@ Resources:
PermissionsBoundary: arn:aws:1234:iam:boundary/OverridePermissionsBoundary
Layers:
- !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2
SnapStart:
ApplyOn: None
ReservedConcurrentExecutions: 100
Loading

0 comments on commit 58a3e3e

Please sign in to comment.