Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lambda-layer-awscli): add update mechanism for AWS CLI #18780

Merged
merged 2 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@aws-cdk/lambda-layer-awscli/awscli.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.22.46
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -eu
scriptdir=$(cd $(dirname $0) && pwd)

package=awscli
tmpfile=_pip.json

curl -LsSf https://pypi.org/pypi/awscli/json > $tmpfile
trap "rm $tmpfile" EXIT
version=$(node -p "require('./${tmpfile}').info.version")

if [[ $version != 1.* ]]; then
echo "Expected version 1.*, got ${version}" >&2
exit 1
fi

echo "AWS CLI is currently at ${version}"

echo $version > $scriptdir/../awscli.version
31 changes: 17 additions & 14 deletions packages/@aws-cdk/lambda-layer-awscli/layer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
FROM public.ecr.aws/lambda/provided:latest

#
# versions
#

# This is the last version that still supports Python 2.7
ARG AWSCLI_VERSION=1.19.112

USER root
RUN mkdir -p /opt
WORKDIR /tmp
Expand All @@ -16,21 +9,24 @@ WORKDIR /tmp
#

RUN yum update -y \
&& yum install -y zip unzip wget tar gzip
&& yum install -y zip unzip wget tar gzip python3

#
# aws cli
#

ARG AWSCLI_VERSION=0.0.0

RUN curl https://s3.amazonaws.com/aws-cli/awscli-bundle-${AWSCLI_VERSION}.zip -o awscli-bundle.zip
RUN unzip awscli-bundle.zip
RUN ./awscli-bundle/install -i /opt/awscli -b /opt/awscli/aws
RUN python3 ./awscli-bundle/install -i /opt/awscli -b /opt/awscli/aws

# organize for self-contained usage
RUN mv /opt/awscli /opt/awscli.tmp
RUN mv /opt/awscli.tmp/lib/python2.7/site-packages /opt/awscli
RUN mv /opt/awscli.tmp/bin /opt/awscli/bin
RUN mv /opt/awscli/bin/aws /opt/awscli
RUN mv /opt/awscli /opt/awscli.tmp
RUN pyver=$(python3 -c 'import sys; v = sys.version_info; print(f"{v[0]}.{v[1]}")') && \
mv /opt/awscli.tmp/lib/python${pyver}/site-packages /opt/awscli
RUN mv /opt/awscli.tmp/bin /opt/awscli/bin
RUN mv /opt/awscli/bin/aws /opt/awscli

# cleanup
RUN rm -fr /opt/awscli.tmp
Expand All @@ -39,6 +35,13 @@ RUN rm -rf \
/opt/awscli/setuptools* \
/opt/awscli/awscli/examples

#
# Test that the CLI works
#

RUN yum install -y groff
RUN /opt/awscli/aws help

#
# create the bundle
#
Expand All @@ -49,4 +52,4 @@ RUN cd /opt \
&& ls -alh /layer.zip;

WORKDIR /
ENTRYPOINT [ "/bin/bash" ]
ENTRYPOINT [ "/bin/bash" ]
6 changes: 4 additions & 2 deletions packages/@aws-cdk/lambda-layer-awscli/layer/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ set -euo pipefail

cd $(dirname $0)

echo ">> Building AWS Lambda layer inside a docker image..."
version=$(cat ../awscli.version)

echo ">> Building AWS Lambda layer inside a docker image for CLI version ${version}..."

TAG='aws-lambda-layer'

docker build -t ${TAG} .
docker build -t ${TAG} . --build-arg AWSCLI_VERSION=${version}

echo ">> Extrating layer.zip from the build container..."
CONTAINER=$(docker run -d ${TAG} false)
Expand Down