├── .eslintignore ├── .github ├── FUNDING.yml └── workflows │ ├── ci-build.yml │ └── ci-run.yml ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── base ├── .dockerignore ├── Dockerfile ├── amazonlinux1.txt ├── base-2 │ ├── Dockerfile │ ├── amazonlinux2.txt │ ├── diff.txt │ ├── dump-packages.sh │ ├── fs.txt │ ├── missing.txt │ └── packages.txt ├── build-2 │ └── Dockerfile ├── build-all-build.sh ├── build-all-run.sh ├── build-all.sh ├── build │ └── Dockerfile ├── create-base-2.sh ├── create-base.sh ├── create-build-2.sh ├── create-build.sh ├── dump-dotnetcore20 │ ├── Function.cs │ ├── Readme.md │ ├── aws-lambda-tools-defaults.json │ └── dump-dotnetcore20.csproj ├── dump-dotnetcore21 │ ├── Function.cs │ ├── Readme.md │ ├── aws-lambda-tools-defaults.json │ └── dump-dotnetcore21.csproj ├── dump-dotnetcore31 │ ├── Function.cs │ ├── aws-lambda-tools-defaults.json │ └── dump-dotnetcore31.csproj ├── dump-go1x │ ├── dump-go1x.go │ ├── go.mod │ └── go.sum ├── dump-java11 │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.buildship.core.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── lambci │ │ └── lambda │ │ └── DumpJava11.java ├── dump-java8 │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.buildship.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── lambci │ │ └── lambda │ │ └── DumpJava8.java ├── dump-java8al2 │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.buildship.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── lambci │ │ └── lambda │ │ └── DumpJava8.java ├── dump-node10x.js ├── dump-node12x.js ├── dump-nodejs.js ├── dump-nodejs43.js ├── dump-nodejs610.js ├── dump-nodejs810.js ├── dump-packages.sh ├── dump-provided.sh ├── dump-providedal2 │ ├── bootstrap.go │ ├── go.mod │ └── go.sum ├── dump-python27.py ├── dump-python36.py ├── dump-python37.py ├── dump-python38.py ├── dump-ruby25.rb ├── dump-ruby27.rb ├── dump.sh ├── native-test.sh ├── packages.txt ├── publish-all.sh ├── runtimes.sh ├── tag-all.sh ├── tar-find-layer │ └── build.sh └── test-all.sh ├── docker-lambda.code-workspace ├── dotnetcore2.0 ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ ├── MockBootstraps │ ├── DebuggerExtensions.cs │ ├── MockBootstraps.csproj │ ├── MockBootstraps.sln │ ├── MockLambdaContext.cs │ ├── MockRuntime.cs │ ├── Program.cs │ └── lib │ │ ├── Amazon.Lambda.Core.dll │ │ ├── Bootstrap.dll │ │ └── Bootstrap.pdb │ └── update_libs.sh ├── dotnetcore2.1 ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ ├── MockBootstraps │ ├── DebuggerExtensions.cs │ ├── MockBootstraps.csproj │ ├── MockBootstraps.sln │ ├── MockLambdaContext.cs │ ├── MockRuntime.cs │ ├── Program.cs │ └── lib │ │ ├── Amazon.Lambda.Core.dll │ │ ├── Bootstrap.dll │ │ └── Bootstrap.pdb │ └── update_libs.sh ├── dotnetcore3.1 ├── build │ └── Dockerfile └── run │ └── Dockerfile ├── examples ├── docker-file │ ├── Dockerfile │ ├── index.js │ └── package.json ├── dotnetcore2.0 │ ├── Function.cs │ ├── README.md │ └── test.csproj ├── dotnetcore2.1 │ ├── Function.cs │ ├── README.md │ ├── test.csproj │ └── test.sln ├── dotnetcore3.1 │ ├── Function.cs │ ├── README.md │ ├── test.csproj │ └── test.sln ├── go1.x │ ├── go.mod │ ├── go.sum │ └── handler.go ├── java │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.buildship.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── README.md │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── lambci │ │ └── lambda │ │ └── ExampleHandler.java ├── nodejs-native-module │ ├── index.js │ ├── package-lock.json │ ├── package.json │ └── test.js ├── nodejs6.10 │ ├── index.js │ └── package.json ├── nodejs8.10 │ ├── index.js │ └── package.json ├── post.lua ├── provided.al2 │ ├── bootstrap.go │ ├── go.mod │ └── go.sum ├── provided │ └── bootstrap ├── python │ └── lambda_function.py ├── ruby │ └── lambda_function.rb └── terminal3.png ├── go1.x ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ ├── aws-lambda-mock.go │ ├── go.mod │ └── go.sum ├── index.js ├── java11 ├── build │ └── Dockerfile └── run │ └── Dockerfile ├── java8.al2 ├── build │ └── Dockerfile └── run │ └── Dockerfile ├── java8 ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ ├── README.md │ └── lambda-runtime-mock │ ├── .classpath │ ├── .project │ ├── .settings │ └── org.eclipse.jdt.core.prefs │ ├── build.sh │ ├── gson-2.3.1.jar │ └── src │ └── main │ └── java │ └── lambdainternal │ └── LambdaRuntime.java ├── nodejs10.x ├── build │ └── Dockerfile └── run │ └── Dockerfile ├── nodejs12.x ├── build │ └── Dockerfile └── run │ └── Dockerfile ├── nodejs4.3 ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ └── awslambda-mock.js ├── nodejs6.10 ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ └── awslambda-mock.js ├── nodejs8.10 ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ └── awslambda-mock.js ├── package.json ├── provided.al2 ├── build │ └── Dockerfile └── run │ └── Dockerfile ├── provided ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ ├── go.mod │ ├── go.sum │ └── init.go ├── python2.7 ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ └── runtime_mock.py ├── python3.6 ├── build │ └── Dockerfile └── run │ ├── Dockerfile │ └── runtime_mock.py ├── python3.7 ├── build │ └── Dockerfile └── run │ └── Dockerfile ├── python3.8 ├── build │ └── Dockerfile └── run │ └── Dockerfile ├── ruby2.5 ├── build │ └── Dockerfile └── run │ └── Dockerfile ├── ruby2.7 ├── build │ └── Dockerfile └── run │ └── Dockerfile └── test.js /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: mhart 4 | -------------------------------------------------------------------------------- /.github/workflows/ci-build.yml: -------------------------------------------------------------------------------- 1 | name: ci-build 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | - name: Build build Docker images 16 | working-directory: base 17 | run: ./build-all-build.sh 18 | - name: List Docker images 19 | run: | 20 | docker images 21 | -------------------------------------------------------------------------------- /.github/workflows/ci-run.yml: -------------------------------------------------------------------------------- 1 | name: ci-run 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | - name: Build run Docker images 16 | working-directory: base 17 | run: ./build-all-run.sh 18 | - name: List Docker images 19 | run: | 20 | docker images 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | base/diff 3 | base/diff-2 4 | *.pyc 5 | *.vs 6 | *.userprefs 7 | .gradle 8 | base/tar-find-layer/layer.zip 9 | base/dump-java8/bin 10 | base/dump-java8/build 11 | base/dump-java8al2/bin 12 | base/dump-java8al2/build 13 | base/dump-java11/bin 14 | base/dump-java11/build 15 | base/dump-dotnetcore20/bin 16 | base/dump-dotnetcore20/obj 17 | base/dump-dotnetcore21/bin 18 | base/dump-dotnetcore21/obj 19 | base/dump-dotnetcore31/bin 20 | base/dump-dotnetcore31/obj 21 | base/dump-providedal2/bootstrap 22 | base/dump-providedal2/bootstrap.zip 23 | dotnetcore2.0/run/MockBootstraps/bin 24 | dotnetcore2.0/run/MockBootstraps/obj 25 | dotnetcore2.1/run/MockBootstraps/bin 26 | dotnetcore2.1/run/MockBootstraps/obj 27 | java8/run/lambda-runtime-mock/target 28 | examples/dotnetcore2.0/bin 29 | examples/dotnetcore2.0/obj 30 | examples/dotnetcore2.0/pub 31 | examples/dotnetcore2.1/bin 32 | examples/dotnetcore2.1/obj 33 | examples/dotnetcore2.1/pub 34 | examples/dotnetcore3.1/bin 35 | examples/dotnetcore3.1/obj 36 | examples/dotnetcore3.1/pub 37 | examples/java/bin 38 | examples/java/build 39 | examples/go1.x/handler 40 | examples/go1.x/handler 41 | examples/provided.al2/bootstrap 42 | package-lock.json 43 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | base 2 | examples 3 | nodejs* 4 | python* 5 | java* 6 | go1* 7 | dotnetcore* 8 | ruby* 9 | provided 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Michael Hart and LambCI contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /base/.dockerignore: -------------------------------------------------------------------------------- 1 | ** 2 | !base*.tgz 3 | -------------------------------------------------------------------------------- /base/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM amazonlinux:1 2 | 3 | # Docker doesn't support unpacking from remote URLs with ADD, 4 | # and we don't want to 'docker import' because we can't squash into a small layer 5 | # So this is expected to be downloaded from https://lambci.s3.amazonaws.com/fs/base.tgz 6 | ADD ./base.tgz /opt/ 7 | 8 | RUN yum --installroot=/opt reinstall -y filesystem-2.4.30-3.8.amzn1 && \ 9 | yum --installroot=/opt clean all 10 | 11 | FROM scratch 12 | 13 | COPY --from=0 /opt / 14 | 15 | ENV PATH=/usr/local/bin:/usr/bin/:/bin:/opt/bin \ 16 | LD_LIBRARY_PATH=/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib \ 17 | LANG=en_US.UTF-8 \ 18 | TZ=:UTC \ 19 | LAMBDA_TASK_ROOT=/var/task \ 20 | LAMBDA_RUNTIME_DIR=/var/runtime \ 21 | _LAMBDA_CONTROL_SOCKET=14 \ 22 | _LAMBDA_SHARED_MEM_FD=11 \ 23 | _LAMBDA_LOG_FD=9 \ 24 | _LAMBDA_SB_ID=7 \ 25 | _LAMBDA_CONSOLE_SOCKET=16 \ 26 | _LAMBDA_RUNTIME_LOAD_TIME=1530232235231 \ 27 | _AWS_XRAY_DAEMON_ADDRESS=169.254.79.2 \ 28 | _AWS_XRAY_DAEMON_PORT=2000 \ 29 | AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000 \ 30 | AWS_XRAY_CONTEXT_MISSING=LOG_ERROR \ 31 | _X_AMZN_TRACE_ID='Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=1' 32 | 33 | # pam has problems reinstalling from a non-standard installroot, 34 | # so reinstall everything except filesystem here 35 | RUN yum reinstall -y setup-2.8.14-20.12.amzn1 audit-libs-2.6.5-3.28.amzn1 shadow-utils-4.1.4.2-13.10.amzn1 \ 36 | openssl-1.0.2k-16.152.amzn1 glibc-2.17-292.180.amzn1 glibc-common-2.17-292.180.amzn1 pam-1.1.8-12.33.amzn1 && \ 37 | yum clean all && \ 38 | chown sbx_user1051:495 /tmp && \ 39 | chmod 700 /tmp 40 | 41 | WORKDIR /var/task 42 | -------------------------------------------------------------------------------- /base/amazonlinux1.txt: -------------------------------------------------------------------------------- 1 | basesystem-10.0-4.9.amzn1.noarch 2 | bash-4.2.46-34.43.amzn1.x86_64 3 | bzip2-libs-1.0.6-8.12.amzn1.x86_64 4 | ca-certificates-2018.2.22-65.1.22.amzn1.noarch 5 | chkconfig-1.3.49.3-2.14.amzn1.x86_64 6 | coreutils-8.22-15.52.amzn1.x86_64 7 | curl-7.61.1-12.95.amzn1.x86_64 8 | cyrus-sasl-lib-2.1.23-13.16.amzn1.x86_64 9 | db4-4.7.25-18.11.amzn1.x86_64 10 | db4-utils-4.7.25-18.11.amzn1.x86_64 11 | elfutils-libelf-0.168-8.19.amzn1.x86_64 12 | expat-2.1.0-11.22.amzn1.x86_64 13 | file-libs-5.37-8.49.amzn1.x86_64 14 | filesystem-2.4.30-3.8.amzn1.x86_64 15 | gawk-3.1.7-10.10.amzn1.x86_64 16 | gdbm-1.8.0-36.6.amzn1.x86_64 17 | glib2-2.36.3-5.21.amzn1.x86_64 18 | glibc-2.17-292.180.amzn1.x86_64 19 | glibc-common-2.17-292.180.amzn1.x86_64 20 | gmp-6.0.0-11.16.amzn1.x86_64 21 | gnupg2-2.0.28-2.33.amzn1.x86_64 22 | gpgme-1.4.3-5.15.amzn1.x86_64 23 | grep-2.20-3.18.amzn1.x86_64 24 | gzip-1.5-9.19.amzn1.x86_64 25 | info-5.1-4.10.amzn1.x86_64 26 | keyutils-libs-1.5.8-3.12.amzn1.x86_64 27 | krb5-libs-1.15.1-46.48.amzn1.x86_64 28 | libacl-2.2.49-6.11.amzn1.x86_64 29 | libassuan-2.0.3-3.3.amzn1.x86_64 30 | libattr-2.4.46-12.10.amzn1.x86_64 31 | libcap-2.16-5.5.8.amzn1.x86_64 32 | libcom_err-1.43.5-2.43.amzn1.x86_64 33 | libcurl-7.61.1-12.95.amzn1.x86_64 34 | libffi-3.0.13-16.5.amzn1.x86_64 35 | libgcc72-7.2.1-2.59.amzn1.x86_64 36 | libgcrypt-1.5.3-12.19.amzn1.x86_64 37 | libgpg-error-1.11-1.12.amzn1.x86_64 38 | libicu-50.2-4.0.amzn1.x86_64 39 | libidn2-2.3.0-1.4.amzn1.x86_64 40 | libnghttp2-1.33.0-1.1.6.amzn1.x86_64 41 | libpsl-0.6.2-1.2.amzn1.x86_64 42 | libselinux-2.1.10-3.22.amzn1.x86_64 43 | libsepol-2.1.7-3.12.amzn1.x86_64 44 | libssh2-1.4.2-3.12.amzn1.x86_64 45 | libstdc++72-7.2.1-2.59.amzn1.x86_64 46 | libtasn1-2.3-6.6.amzn1.x86_64 47 | libunistring-0.9.3-6.1.amzn1.x86_64 48 | libverto-0.2.5-4.9.amzn1.x86_64 49 | libxml2-2.9.1-6.4.41.amzn1.x86_64 50 | libxml2-python27-2.9.1-6.4.41.amzn1.x86_64 51 | lua-5.1.4-4.1.9.amzn1.x86_64 52 | make-3.82-21.10.amzn1.x86_64 53 | ncurses-5.7-4.20090207.14.amzn1.x86_64 54 | ncurses-base-5.7-4.20090207.14.amzn1.x86_64 55 | ncurses-libs-5.7-4.20090207.14.amzn1.x86_64 56 | nspr-4.21.0-1.43.amzn1.x86_64 57 | nss-3.44.0-7.84.amzn1.x86_64 58 | nss-pem-1.0.3-4.3.amzn1.x86_64 59 | nss-softokn-3.44.0-8.44.amzn1.x86_64 60 | nss-softokn-freebl-3.44.0-8.44.amzn1.x86_64 61 | nss-sysinit-3.44.0-7.84.amzn1.x86_64 62 | nss-tools-3.44.0-7.84.amzn1.x86_64 63 | nss-util-3.44.0-4.56.amzn1.x86_64 64 | openldap-2.4.40-16.31.amzn1.x86_64 65 | openssl-1.0.2k-16.151.amzn1.x86_64 66 | p11-kit-0.18.5-2.3.amzn1.x86_64 67 | p11-kit-trust-0.18.5-2.3.amzn1.x86_64 68 | pcre-8.21-7.8.amzn1.x86_64 69 | pinentry-0.7.6-6.11.amzn1.x86_64 70 | pkgconfig-0.27.1-2.7.amzn1.x86_64 71 | popt-1.13-7.7.amzn1.x86_64 72 | pth-2.0.7-9.3.7.amzn1.x86_64 73 | python27-2.7.18-2.140.amzn1.x86_64 74 | python27-chardet-2.0.1-7.7.amzn1.noarch 75 | python27-iniparse-0.3.1-2.1.9.amzn1.noarch 76 | python27-kitchen-1.1.1-5.6.amzn1.noarch 77 | python27-libs-2.7.18-2.140.amzn1.x86_64 78 | python27-pycurl-7.19.0-17.12.amzn1.x86_64 79 | python27-pygpgme-0.3-9.12.amzn1.x86_64 80 | python27-pyliblzma-0.5.3-11.6.amzn1.x86_64 81 | python27-pyxattr-0.5.0-1.6.amzn1.x86_64 82 | python27-urlgrabber-3.10-8.16.amzn1.noarch 83 | readline-6.2-9.14.amzn1.x86_64 84 | rpm-4.11.3-40.78.amzn1.x86_64 85 | rpm-build-libs-4.11.3-40.78.amzn1.x86_64 86 | rpm-libs-4.11.3-40.78.amzn1.x86_64 87 | rpm-python27-4.11.3-40.78.amzn1.x86_64 88 | sed-4.2.1-10.10.amzn1.x86_64 89 | setup-2.8.14-20.12.amzn1.noarch 90 | shared-mime-info-1.1-9.8.amzn1.x86_64 91 | sqlite-3.7.17-8.14.amzn1.x86_64 92 | sysctl-defaults-1.0-1.1.amzn1.noarch 93 | system-release-2018.03-0.0.noarch 94 | tar-1.26-31.22.amzn1.x86_64 95 | tzdata-2020a-1.75.amzn1.noarch 96 | xz-libs-5.2.2-1.13.amzn1.x86_64 97 | yum-3.4.3-150.71.amzn1.noarch 98 | yum-metadata-parser-1.1.4-10.20.amzn1.x86_64 99 | yum-plugin-ovl-1.1.31-46.30.amzn1.noarch 100 | yum-plugin-priorities-1.1.31-46.30.amzn1.noarch 101 | yum-utils-1.1.31-46.30.amzn1.noarch 102 | zlib-1.2.8-7.18.amzn1.x86_64 103 | -------------------------------------------------------------------------------- /base/base-2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM amazonlinux:2 2 | 3 | # Docker doesn't support unpacking from remote URLs with ADD, 4 | # and we don't want to 'docker import' because we can't squash into a small layer 5 | # So this is expected to be downloaded from https://lambci.s3.amazonaws.com/fs/base-2.tgz 6 | ADD ./base-2.tgz /opt/ 7 | 8 | RUN yum --installroot=/opt reinstall -y filesystem-3.2-25.amzn2.0.4 \ 9 | setup-2.8.71-10.amzn2.0.1 glibc-2.26-39.amzn2 glibc-common-2.26-39.amzn2 && \ 10 | yum --installroot=/opt clean all 11 | 12 | FROM scratch 13 | 14 | COPY --from=0 /opt / 15 | 16 | ENV PATH=/usr/local/bin:/usr/bin/:/bin:/opt/bin \ 17 | LD_LIBRARY_PATH=/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib \ 18 | LANG=en_US.UTF-8 \ 19 | TZ=:UTC \ 20 | LAMBDA_TASK_ROOT=/var/task \ 21 | LAMBDA_RUNTIME_DIR=/var/runtime \ 22 | _LAMBDA_CONTROL_SOCKET=14 \ 23 | _LAMBDA_SHARED_MEM_FD=11 \ 24 | _LAMBDA_LOG_FD=9 \ 25 | _LAMBDA_SB_ID=7 \ 26 | _LAMBDA_CONSOLE_SOCKET=16 \ 27 | _LAMBDA_RUNTIME_LOAD_TIME=1530232235231 \ 28 | _AWS_XRAY_DAEMON_ADDRESS=169.254.79.2 \ 29 | _AWS_XRAY_DAEMON_PORT=2000 \ 30 | AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000 \ 31 | AWS_XRAY_CONTEXT_MISSING=LOG_ERROR \ 32 | _X_AMZN_TRACE_ID='Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=1' 33 | 34 | RUN chown sbx_user1051:495 /tmp && \ 35 | chmod 700 /tmp 36 | 37 | WORKDIR /var/task 38 | -------------------------------------------------------------------------------- /base/base-2/amazonlinux2.txt: -------------------------------------------------------------------------------- 1 | amazon-linux-extras-1.6.12-1.amzn2.noarch 2 | basesystem-10.0-7.amzn2.0.1.noarch 3 | bash-4.2.46-34.amzn2.x86_64 4 | bzip2-libs-1.0.6-13.amzn2.0.2.x86_64 5 | ca-certificates-2019.2.32-76.amzn2.0.3.noarch 6 | chkconfig-1.7.4-1.amzn2.0.2.x86_64 7 | coreutils-8.22-24.amzn2.x86_64 8 | cpio-2.11-28.amzn2.x86_64 9 | curl-7.61.1-12.amzn2.0.2.x86_64 10 | cyrus-sasl-lib-2.1.26-23.amzn2.x86_64 11 | diffutils-3.3-5.amzn2.x86_64 12 | elfutils-libelf-0.176-2.amzn2.x86_64 13 | expat-2.1.0-12.amzn2.x86_64 14 | file-libs-5.11-36.amzn2.0.1.x86_64 15 | filesystem-3.2-25.amzn2.0.4.x86_64 16 | findutils-4.5.11-6.amzn2.x86_64 17 | gawk-4.0.2-4.amzn2.1.2.x86_64 18 | gdbm-1.13-6.amzn2.0.2.x86_64 19 | glib2-2.56.1-7.amzn2.0.1.x86_64 20 | glibc-2.26-38.amzn2.x86_64 21 | glibc-common-2.26-38.amzn2.x86_64 22 | glibc-langpack-en-2.26-38.amzn2.x86_64 23 | glibc-minimal-langpack-2.26-38.amzn2.x86_64 24 | gmp-6.0.0-15.amzn2.0.2.x86_64 25 | gnupg2-2.0.22-5.amzn2.0.4.x86_64 26 | gpgme-1.3.2-5.amzn2.0.2.x86_64 27 | grep-2.20-3.amzn2.0.2.x86_64 28 | info-5.1-5.amzn2.x86_64 29 | keyutils-libs-1.5.8-3.amzn2.0.2.x86_64 30 | krb5-libs-1.15.1-37.amzn2.2.2.x86_64 31 | libacl-2.2.51-14.amzn2.x86_64 32 | libassuan-2.1.0-3.amzn2.0.2.x86_64 33 | libattr-2.4.46-12.amzn2.0.2.x86_64 34 | libblkid-2.30.2-2.amzn2.0.4.x86_64 35 | libcap-2.22-9.amzn2.0.2.x86_64 36 | libcom_err-1.42.9-19.amzn2.x86_64 37 | libcrypt-2.26-38.amzn2.x86_64 38 | libcurl-7.61.1-12.amzn2.0.2.x86_64 39 | libdb-5.3.21-24.amzn2.0.3.x86_64 40 | libdb-utils-5.3.21-24.amzn2.0.3.x86_64 41 | libffi-3.0.13-18.amzn2.0.2.x86_64 42 | libgcc-7.3.1-9.amzn2.x86_64 43 | libgcrypt-1.5.3-14.amzn2.0.2.x86_64 44 | libgpg-error-1.12-3.amzn2.0.3.x86_64 45 | libidn2-2.3.0-1.amzn2.x86_64 46 | libmetalink-0.1.3-13.amzn2.x86_64 47 | libmount-2.30.2-2.amzn2.0.4.x86_64 48 | libnghttp2-1.41.0-1.amzn2.x86_64 49 | libselinux-2.5-12.amzn2.0.2.x86_64 50 | libsepol-2.5-8.1.amzn2.0.2.x86_64 51 | libssh2-1.4.3-12.amzn2.2.3.x86_64 52 | libstdc++-7.3.1-9.amzn2.x86_64 53 | libtasn1-4.10-1.amzn2.0.2.x86_64 54 | libunistring-0.9.3-9.amzn2.0.2.x86_64 55 | libuuid-2.30.2-2.amzn2.0.4.x86_64 56 | libverto-0.2.5-4.amzn2.0.2.x86_64 57 | libxml2-2.9.1-6.amzn2.5.1.x86_64 58 | lua-5.1.4-15.amzn2.0.2.x86_64 59 | ncurses-6.0-8.20170212.amzn2.1.3.x86_64 60 | ncurses-base-6.0-8.20170212.amzn2.1.3.noarch 61 | ncurses-libs-6.0-8.20170212.amzn2.1.3.x86_64 62 | nspr-4.25.0-2.amzn2.x86_64 63 | nss-3.53.1-3.amzn2.x86_64 64 | nss-pem-1.0.3-5.amzn2.x86_64 65 | nss-softokn-3.53.1-6.amzn2.x86_64 66 | nss-softokn-freebl-3.53.1-6.amzn2.x86_64 67 | nss-sysinit-3.53.1-3.amzn2.x86_64 68 | nss-tools-3.53.1-3.amzn2.x86_64 69 | nss-util-3.53.1-1.amzn2.x86_64 70 | openldap-2.4.44-22.amzn2.x86_64 71 | openssl-libs-1.0.2k-19.amzn2.0.3.x86_64 72 | p11-kit-0.23.21-2.amzn2.0.1.x86_64 73 | p11-kit-trust-0.23.21-2.amzn2.0.1.x86_64 74 | pcre-8.32-17.amzn2.0.2.x86_64 75 | pinentry-0.8.1-17.amzn2.0.2.x86_64 76 | popt-1.13-16.amzn2.0.2.x86_64 77 | pth-2.0.7-23.amzn2.0.2.x86_64 78 | pygpgme-0.3-9.amzn2.0.2.x86_64 79 | pyliblzma-0.5.3-11.amzn2.0.2.x86_64 80 | python-2.7.18-1.amzn2.0.2.x86_64 81 | python-iniparse-0.4-9.amzn2.noarch 82 | python-libs-2.7.18-1.amzn2.0.2.x86_64 83 | python-pycurl-7.19.0-19.amzn2.0.2.x86_64 84 | python-urlgrabber-3.10-9.amzn2.0.1.noarch 85 | python2-rpm-4.11.3-40.amzn2.0.5.x86_64 86 | pyxattr-0.5.1-5.amzn2.0.2.x86_64 87 | readline-6.2-10.amzn2.0.2.x86_64 88 | rpm-4.11.3-40.amzn2.0.5.x86_64 89 | rpm-build-libs-4.11.3-40.amzn2.0.5.x86_64 90 | rpm-libs-4.11.3-40.amzn2.0.5.x86_64 91 | sed-4.2.2-5.amzn2.0.2.x86_64 92 | setup-2.8.71-10.amzn2.0.1.noarch 93 | shared-mime-info-1.8-4.amzn2.x86_64 94 | sqlite-3.7.17-8.amzn2.1.1.x86_64 95 | system-release-2-12.amzn2.x86_64 96 | tzdata-2020a-1.amzn2.noarch 97 | vim-minimal-8.1.1602-1.amzn2.x86_64 98 | xz-libs-5.2.2-1.amzn2.0.2.x86_64 99 | yum-3.4.3-158.amzn2.0.4.noarch 100 | yum-metadata-parser-1.1.4-10.amzn2.0.2.x86_64 101 | yum-plugin-ovl-1.1.31-46.amzn2.0.1.noarch 102 | yum-plugin-priorities-1.1.31-46.amzn2.0.1.noarch 103 | zlib-1.2.7-18.amzn2.x86_64 104 | -------------------------------------------------------------------------------- /base/base-2/diff.txt: -------------------------------------------------------------------------------- 1 | amazon-linux-extras-1.6.11-1.amzn2.noarch 2 | bzip2-libs-1.0.6-13.amzn2.0.2.x86_64 3 | cpio-2.11-27.amzn2.x86_64 4 | curl-7.61.1-12.amzn2.0.1.x86_64 5 | cyrus-sasl-lib-2.1.26-23.amzn2.x86_64 6 | diffutils-3.3-5.amzn2.x86_64 7 | elfutils-libelf-0.176-2.amzn2.x86_64 8 | expat-2.1.0-10.amzn2.0.2.x86_64 9 | file-libs-5.11-35.amzn2.0.2.x86_64 10 | findutils-4.5.11-6.amzn2.x86_64 11 | gdbm-1.13-6.amzn2.0.2.x86_64 12 | glib2-2.56.1-5.amzn2.0.1.x86_64 13 | glibc-langpack-en-2.26-34.amzn2.x86_64 14 | gnupg2-2.0.22-5.amzn2.0.4.x86_64 15 | gpgme-1.3.2-5.amzn2.0.2.x86_64 16 | libassuan-2.1.0-3.amzn2.0.2.x86_64 17 | libblkid-2.30.2-2.amzn2.0.4.x86_64 18 | libcrypt-2.26-34.amzn2.x86_64 19 | libcurl-7.61.1-12.amzn2.0.1.x86_64 20 | libdb-5.3.21-24.amzn2.0.3.x86_64 21 | libdb-utils-5.3.21-24.amzn2.0.3.x86_64 22 | libgcrypt-1.5.3-14.amzn2.0.2.x86_64 23 | libgpg-error-1.12-3.amzn2.0.3.x86_64 24 | libidn2-2.3.0-1.amzn2.x86_64 25 | libmetalink-0.1.2-7.amzn2.0.2.x86_64 26 | libmount-2.30.2-2.amzn2.0.4.x86_64 27 | libnghttp2-1.39.2-1.amzn2.x86_64 28 | libssh2-1.4.3-12.amzn2.2.2.x86_64 29 | libunistring-0.9.3-9.amzn2.0.2.x86_64 30 | libuuid-2.30.2-2.amzn2.0.4.x86_64 31 | libxml2-2.9.1-6.amzn2.3.3.x86_64 32 | lua-5.1.4-15.amzn2.0.2.x86_64 33 | nss-3.44.0-7.amzn2.x86_64 34 | nss-pem-1.0.3-5.amzn2.x86_64 35 | nss-softokn-3.44.0-8.amzn2.x86_64 36 | nss-sysinit-3.44.0-7.amzn2.x86_64 37 | nss-tools-3.44.0-7.amzn2.x86_64 38 | openldap-2.4.44-15.amzn2.x86_64 39 | pinentry-0.8.1-17.amzn2.0.2.x86_64 40 | pth-2.0.7-23.amzn2.0.2.x86_64 41 | pygpgme-0.3-9.amzn2.0.2.x86_64 42 | pyliblzma-0.5.3-11.amzn2.0.2.x86_64 43 | python-2.7.18-1.amzn2.x86_64 44 | python-iniparse-0.4-9.amzn2.noarch 45 | python-libs-2.7.18-1.amzn2.x86_64 46 | python-pycurl-7.19.0-19.amzn2.0.2.x86_64 47 | python-urlgrabber-3.10-9.amzn2.0.1.noarch 48 | python2-rpm-4.11.3-40.amzn2.0.4.x86_64 49 | pyxattr-0.5.1-5.amzn2.0.2.x86_64 50 | readline-6.2-10.amzn2.0.2.x86_64 51 | rpm-4.11.3-40.amzn2.0.4.x86_64 52 | rpm-build-libs-4.11.3-40.amzn2.0.4.x86_64 53 | rpm-libs-4.11.3-40.amzn2.0.4.x86_64 54 | shared-mime-info-1.8-4.amzn2.x86_64 55 | sqlite-3.7.17-8.amzn2.1.1.x86_64 56 | vim-minimal-8.1.1602-1.amzn2.x86_64 57 | xz-libs-5.2.2-1.amzn2.0.2.x86_64 58 | yum-3.4.3-158.amzn2.0.4.noarch 59 | yum-metadata-parser-1.1.4-10.amzn2.0.2.x86_64 60 | yum-plugin-ovl-1.1.31-46.amzn2.0.1.noarch 61 | yum-plugin-priorities-1.1.31-46.amzn2.0.1.noarch 62 | -------------------------------------------------------------------------------- /base/base-2/dump-packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | curl https://lambci.s3.amazonaws.com/fs/base-2.tgz | tar -xz --strip-components=2 -- var/lib/rpm 4 | 5 | docker pull amazonlinux:2 6 | docker run -v "$PWD/rpm":/rpm --rm amazonlinux:2 rpm -qa --dbpath /rpm | grep -v ^gpg-pubkey- | sort > packages.txt 7 | rm -rf rpm 8 | 9 | docker run --rm amazonlinux:2 bash -c 'yum upgrade -y > /dev/null && rpm -qa' | grep -v ^gpg-pubkey- | sort > amazonlinux2.txt 10 | 11 | if diff -w -d amazonlinux2.txt packages.txt | grep -q '>'; then 12 | echo 'Mismatching packages on images' 13 | diff -w -d amazonlinux2.txt packages.txt 14 | else 15 | diff -w -d amazonlinux2.txt packages.txt | grep '<' | awk '{print $2}' > diff.txt 16 | fi 17 | -------------------------------------------------------------------------------- /base/base-2/missing.txt: -------------------------------------------------------------------------------- 1 | /etc/securetty 2 | /etc/shadow 3 | /etc/gshadow 4 | /var/log/yum.log 5 | /var/lib/yum/history/2019-04-17/1 6 | /var/lib/yum/history/history-2019-04-17.sqlite 7 | /var/cache/ldconfig 8 | /usr/sbin/build-locale-archive 9 | /usr/sbin/glibc_post_upgrade.x86_64 10 | /root/ 11 | -------------------------------------------------------------------------------- /base/base-2/packages.txt: -------------------------------------------------------------------------------- 1 | basesystem-10.0-7.amzn2.0.1.noarch 2 | bash-4.2.46-34.amzn2.x86_64 3 | ca-certificates-2019.2.32-76.amzn2.0.3.noarch 4 | chkconfig-1.7.4-1.amzn2.0.2.x86_64 5 | coreutils-8.22-24.amzn2.x86_64 6 | filesystem-3.2-25.amzn2.0.4.x86_64 7 | gawk-4.0.2-4.amzn2.1.2.x86_64 8 | glibc-2.26-38.amzn2.x86_64 9 | glibc-all-langpacks-2.26-38.amzn2.x86_64 10 | glibc-common-2.26-38.amzn2.x86_64 11 | glibc-minimal-langpack-2.26-38.amzn2.x86_64 12 | gmp-6.0.0-15.amzn2.0.2.x86_64 13 | grep-2.20-3.amzn2.0.2.x86_64 14 | info-5.1-5.amzn2.x86_64 15 | keyutils-libs-1.5.8-3.amzn2.0.2.x86_64 16 | krb5-libs-1.15.1-37.amzn2.2.2.x86_64 17 | libacl-2.2.51-14.amzn2.x86_64 18 | libattr-2.4.46-12.amzn2.0.2.x86_64 19 | libcap-2.22-9.amzn2.0.2.x86_64 20 | libcom_err-1.42.9-19.amzn2.x86_64 21 | libffi-3.0.13-18.amzn2.0.2.x86_64 22 | libgcc-7.3.1-9.amzn2.x86_64 23 | libicu-50.2-4.amzn2.x86_64 24 | libselinux-2.5-12.amzn2.0.2.x86_64 25 | libsepol-2.5-8.1.amzn2.0.2.x86_64 26 | libstdc++-7.3.1-9.amzn2.x86_64 27 | libtasn1-4.10-1.amzn2.0.2.x86_64 28 | libverto-0.2.5-4.amzn2.0.2.x86_64 29 | ncurses-6.0-8.20170212.amzn2.1.3.x86_64 30 | ncurses-base-6.0-8.20170212.amzn2.1.3.noarch 31 | ncurses-libs-6.0-8.20170212.amzn2.1.3.x86_64 32 | nspr-4.25.0-2.amzn2.x86_64 33 | nss-softokn-freebl-3.53.1-6.amzn2.x86_64 34 | nss-util-3.53.1-1.amzn2.x86_64 35 | openssl-libs-1.0.2k-19.amzn2.0.3.x86_64 36 | p11-kit-0.23.21-2.amzn2.0.1.x86_64 37 | p11-kit-trust-0.23.21-2.amzn2.0.1.x86_64 38 | pcre-8.32-17.amzn2.0.2.x86_64 39 | popt-1.13-16.amzn2.0.2.x86_64 40 | sed-4.2.2-5.amzn2.0.2.x86_64 41 | setup-2.8.71-10.amzn2.0.1.noarch 42 | system-release-2-12.amzn2.x86_64 43 | tzdata-2020a-1.amzn2.noarch 44 | zlib-1.2.7-18.amzn2.x86_64 45 | -------------------------------------------------------------------------------- /base/build-2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base-2 2 | 3 | FROM amazonlinux:2 4 | 5 | COPY --from=0 / /opt/ 6 | 7 | RUN yum --installroot=/opt install -y yum yum-plugin-ovl yum-plugin-priorities 8 | 9 | FROM lambci/lambda-base-2 10 | 11 | ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin \ 12 | PIPX_BIN_DIR=/usr/local/bin \ 13 | PIPX_HOME=/usr/local/pipx 14 | 15 | COPY --from=1 /opt / 16 | 17 | RUN chown root:root /tmp && \ 18 | chmod 1777 /tmp && \ 19 | yum install -y glibc-langpack-en && \ 20 | yum groupinstall -y development && \ 21 | yum install -y which clang cmake python-devel python3-devel amazon-linux-extras && \ 22 | amazon-linux-extras install -y docker && \ 23 | yum clean all && \ 24 | pip3 install -U pip setuptools wheel --no-cache-dir && \ 25 | pip3 install pipx --no-cache-dir 26 | -------------------------------------------------------------------------------- /base/build-all-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | source ${PWD}/runtimes.sh 5 | 6 | TOP_DIR="${PWD}/.." 7 | 8 | for RUNTIME in $RUNTIMES; do 9 | echo build-${RUNTIME} 10 | 11 | cd ${TOP_DIR}/${RUNTIME}/build 12 | 13 | docker build -t lambci/lambda:build-${RUNTIME} . 14 | done 15 | -------------------------------------------------------------------------------- /base/build-all-run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | source ${PWD}/runtimes.sh 5 | 6 | TOP_DIR="${PWD}/.." 7 | 8 | for RUNTIME in $RUNTIMES; do 9 | echo $RUNTIME 10 | 11 | cd ${TOP_DIR}/${RUNTIME}/run 12 | 13 | [ -x ./update_libs.sh ] && ./update_libs.sh 14 | 15 | docker build --no-cache -t lambci/lambda:${RUNTIME} . 16 | done 17 | -------------------------------------------------------------------------------- /base/build-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | ${PWD}/build-all-run.sh 5 | 6 | ${PWD}/build-all-build.sh 7 | -------------------------------------------------------------------------------- /base/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base 2 | 3 | ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin \ 4 | PIPX_BIN_DIR=/usr/local/bin \ 5 | PIPX_HOME=/usr/local/pipx 6 | 7 | RUN chown root:root /tmp && \ 8 | chmod 1777 /tmp && \ 9 | yum groups mark convert && \ 10 | yum groupinstall -y development && \ 11 | yum install -y clang cmake docker python27-devel python36-devel \ 12 | ImageMagick-devel-6.9.10.68 cairo-devel libssh2-devel libxslt-devel libmpc-devel readline-devel db4-devel \ 13 | libffi-devel expat-devel libicu-devel lua-devel gdbm-devel sqlite-devel pcre-devel libcurl-devel && \ 14 | yum clean all && \ 15 | alternatives --set gcc /usr/bin/gcc48 && \ 16 | alternatives --set g++ /usr/bin/g++48 && \ 17 | alternatives --set cpp /usr/bin/cpp48 && \ 18 | python3 -m pip install -U pip setuptools wheel --no-cache-dir && \ 19 | pip install pipx --no-cache-dir && \ 20 | pipx run awscli==1.* 2>/dev/null || true 21 | -------------------------------------------------------------------------------- /base/create-base-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl -O https://lambci.s3.amazonaws.com/fs/base-2.tgz 4 | 5 | docker build --squash -t lambci/lambda-base-2 -f ./base-2/Dockerfile . 6 | 7 | rm ./base-2.tgz 8 | -------------------------------------------------------------------------------- /base/create-base.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl -O https://lambci.s3.amazonaws.com/fs/base.tgz 4 | 5 | docker build --squash -t lambci/lambda-base . 6 | 7 | rm ./base.tgz 8 | -------------------------------------------------------------------------------- /base/create-build-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | docker build --no-cache --squash -t lambci/lambda-base-2:build -f ./build-2/Dockerfile . 4 | -------------------------------------------------------------------------------- /base/create-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | docker build --no-cache -t lambci/lambda-base:build -f ./build/Dockerfile . 4 | -------------------------------------------------------------------------------- /base/dump-dotnetcore20/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda.Core; 7 | using Amazon.S3; 8 | 9 | [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 10 | 11 | namespace dump_dotnetcore20 12 | { 13 | public class Function 14 | { 15 | /// 16 | /// Lambda function to dump the container directories /var/lang 17 | /// and /var/runtime and upload the resulting archive to S3 18 | /// 19 | /// 20 | public async Task FunctionHandler(object invokeEvent, ILambdaContext context) 21 | { 22 | string filename = "dotnetcore2.0.tgz"; 23 | string cmd = $"tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read /var/runtime /var/lang"; 24 | 25 | Console.WriteLine($"invokeEvent: {invokeEvent}"); 26 | Console.WriteLine($"context.RemainingTime: {context.RemainingTime}"); 27 | 28 | Console.WriteLine("Parent cmdline:"); 29 | Console.WriteLine(File.ReadAllText("/proc/1/cmdline").Replace("\0", " ")); 30 | 31 | Console.WriteLine("Parent env:"); 32 | RunShell("xargs --null --max-args=1 < /proc/1/environ"); 33 | 34 | Console.WriteLine("This cmdline:"); 35 | Console.WriteLine(File.ReadAllText($"/proc/{Process.GetCurrentProcess().Id}/cmdline").Replace("\0", " ")); 36 | 37 | Console.WriteLine("This env:"); 38 | RunShell($"xargs --null --max-args=1 < /proc/{Process.GetCurrentProcess().Id}/environ"); 39 | 40 | Console.WriteLine($"Current working directory: {Directory.GetCurrentDirectory()}"); 41 | 42 | RunShell(cmd); 43 | 44 | Console.WriteLine("Zipping done! Uploading..."); 45 | 46 | var s3Client = new AmazonS3Client(); 47 | var response = await s3Client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest 48 | { 49 | BucketName = "lambci", 50 | Key = $"fs/{filename}", 51 | FilePath = $"/tmp/{filename}", 52 | CannedACL = S3CannedACL.PublicRead, 53 | }); 54 | 55 | Console.WriteLine("Uploading done!"); 56 | 57 | return response.HttpStatusCode.ToString(); 58 | } 59 | 60 | private static Process RunShell(string cmd) 61 | { 62 | var escapedArgs = cmd.Replace("\"", "\\\""); 63 | var process = new Process 64 | { 65 | StartInfo = new ProcessStartInfo 66 | { 67 | FileName = "/bin/sh", 68 | Arguments = $"-c \"{escapedArgs}\"", 69 | UseShellExecute = false, 70 | CreateNoWindow = true, 71 | } 72 | }; 73 | process.Start(); 74 | process.WaitForExit(); 75 | return process; 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /base/dump-dotnetcore20/Readme.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda Dump Runtime Project 2 | This functions dumps the runtime and uploads it to s3. 3 | 4 | 5 | ## Here are some steps to follow from Visual Studio: 6 | 7 | To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 8 | 9 | To view your deployed function open its Function View window by double-clicking the function name shown beneath the AWS Lambda node in the AWS Explorer tree. 10 | 11 | To perform testing against your deployed function use the Test Invoke tab in the opened Function View window. 12 | 13 | To configure event sources for your deployed function, for example to have your function invoked when an object is created in an Amazon S3 bucket, use the Event Sources tab in the opened Function View window. 14 | 15 | To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window. 16 | 17 | To view execution logs of invocations of your function use the Logs tab in the opened Function View window. 18 | 19 | ## Here are some steps to follow to get started from the command line: 20 | 21 | Restore dependencies 22 | ```shell 23 | dotnet restore 24 | ``` 25 | 26 | Deploy function to AWS Lambda 27 | ```shell 28 | dotnet lambda deploy-function [--profile ] [--region ] dump-dotnetcore20 29 | ``` 30 | 31 | Invoke function 32 | ```shell 33 | dotnet lambda invoke-function [--profile ] [--region ] dump-dotnetcore20 34 | ``` 35 | -------------------------------------------------------------------------------- /base/dump-dotnetcore20/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "configuration": "Release", 3 | "framework": "netcoreapp2.0", 4 | "function-runtime": "dotnetcore2.0", 5 | "function-memory-size": 1536, 6 | "function-timeout": 300, 7 | "function-handler": "dump_dotnetcore20::dump_dotnetcore20.Function::FunctionHandler" 8 | } 9 | -------------------------------------------------------------------------------- /base/dump-dotnetcore20/dump-dotnetcore20.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | true 6 | dump_dotnetcore20 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /base/dump-dotnetcore21/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda.Core; 7 | using Amazon.S3; 8 | 9 | [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 10 | 11 | namespace dump_dotnetcore21 12 | { 13 | public class Function 14 | { 15 | /// 16 | /// Lambda function to dump the container directories /var/lang 17 | /// and /var/runtime and upload the resulting archive to S3 18 | /// 19 | /// 20 | public async Task FunctionHandler(object invokeEvent, ILambdaContext context) 21 | { 22 | string filename = "dotnetcore2.1.tgz"; 23 | string cmd = $"tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read /var/runtime /var/lang"; 24 | 25 | Console.WriteLine($"invokeEvent: {invokeEvent}"); 26 | Console.WriteLine($"context.RemainingTime: {context.RemainingTime}"); 27 | 28 | Console.WriteLine("Parent cmdline:"); 29 | Console.WriteLine(File.ReadAllText("/proc/1/cmdline").Replace("\0", " ")); 30 | 31 | Console.WriteLine("Parent env:"); 32 | RunShell("xargs --null --max-args=1 < /proc/1/environ"); 33 | 34 | Console.WriteLine("This cmdline:"); 35 | Console.WriteLine(File.ReadAllText($"/proc/{Process.GetCurrentProcess().Id}/cmdline").Replace("\0", " ")); 36 | 37 | Console.WriteLine("This env:"); 38 | RunShell($"xargs --null --max-args=1 < /proc/{Process.GetCurrentProcess().Id}/environ"); 39 | 40 | Console.WriteLine($"Current working directory: {Directory.GetCurrentDirectory()}"); 41 | 42 | RunShell(cmd); 43 | 44 | Console.WriteLine("Zipping done! Uploading..."); 45 | 46 | var s3Client = new AmazonS3Client(); 47 | var response = await s3Client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest 48 | { 49 | BucketName = "lambci", 50 | Key = $"fs/{filename}", 51 | FilePath = $"/tmp/{filename}", 52 | CannedACL = S3CannedACL.PublicRead, 53 | }); 54 | 55 | Console.WriteLine("Uploading done!"); 56 | 57 | return response.HttpStatusCode.ToString(); 58 | } 59 | 60 | private static Process RunShell(string cmd) 61 | { 62 | var escapedArgs = cmd.Replace("\"", "\\\""); 63 | var process = new Process 64 | { 65 | StartInfo = new ProcessStartInfo 66 | { 67 | FileName = "/bin/sh", 68 | Arguments = $"-c \"{escapedArgs}\"", 69 | UseShellExecute = false, 70 | CreateNoWindow = true, 71 | } 72 | }; 73 | process.Start(); 74 | process.WaitForExit(); 75 | return process; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /base/dump-dotnetcore21/Readme.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda Dump Runtime Project 2 | This functions dumps the runtime and uploads it to s3. 3 | 4 | 5 | ## Here are some steps to follow from Visual Studio: 6 | 7 | To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 8 | 9 | To view your deployed function open its Function View window by double-clicking the function name shown beneath the AWS Lambda node in the AWS Explorer tree. 10 | 11 | To perform testing against your deployed function use the Test Invoke tab in the opened Function View window. 12 | 13 | To configure event sources for your deployed function, for example to have your function invoked when an object is created in an Amazon S3 bucket, use the Event Sources tab in the opened Function View window. 14 | 15 | To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window. 16 | 17 | To view execution logs of invocations of your function use the Logs tab in the opened Function View window. 18 | 19 | ## Here are some steps to follow to get started from the command line: 20 | 21 | Restore dependencies 22 | ```shell 23 | dotnet restore 24 | ``` 25 | 26 | Deploy function to AWS Lambda 27 | ```shell 28 | dotnet lambda deploy-function [--profile ] [--region ] dump-dotnetcore21 29 | ``` 30 | 31 | Invoke function 32 | ```shell 33 | dotnet lambda invoke-function [--profile ] [--region ] dump-dotnetcore21 34 | ``` 35 | -------------------------------------------------------------------------------- /base/dump-dotnetcore21/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "configuration": "Release", 3 | "framework": "netcoreapp2.1", 4 | "function-runtime": "dotnetcore2.1", 5 | "function-memory-size": 1536, 6 | "function-timeout": 300, 7 | "function-handler": "dump_dotnetcore21::dump_dotnetcore21.Function::FunctionHandler" 8 | } 9 | -------------------------------------------------------------------------------- /base/dump-dotnetcore21/dump-dotnetcore21.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | true 6 | dump_dotnetcore21 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /base/dump-dotnetcore31/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda.Core; 7 | using Amazon.S3; 8 | 9 | [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 10 | 11 | namespace dump_dotnetcore31 12 | { 13 | public class Function 14 | { 15 | /// 16 | /// Lambda function to dump the container directories /var/lang 17 | /// and /var/runtime and upload the resulting archive to S3 18 | /// 19 | /// 20 | public async Task FunctionHandler(object invokeEvent, ILambdaContext context) 21 | { 22 | string filename = "dotnetcore3.1.tgz"; 23 | string cmd = $"tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read /var/runtime /var/lang"; 24 | 25 | Console.WriteLine($"invokeEvent: {invokeEvent}"); 26 | Console.WriteLine($"context.RemainingTime: {context.RemainingTime}"); 27 | 28 | Console.WriteLine("Parent cmdline:"); 29 | Console.WriteLine(File.ReadAllText("/proc/1/cmdline").Replace("\0", " ")); 30 | 31 | Console.WriteLine("Parent env:"); 32 | RunShell("xargs --null --max-args=1 < /proc/1/environ"); 33 | 34 | Console.WriteLine("This cmdline:"); 35 | Console.WriteLine(File.ReadAllText($"/proc/{Process.GetCurrentProcess().Id}/cmdline").Replace("\0", " ")); 36 | 37 | Console.WriteLine("This env:"); 38 | RunShell($"xargs --null --max-args=1 < /proc/{Process.GetCurrentProcess().Id}/environ"); 39 | 40 | Console.WriteLine($"Current working directory: {Directory.GetCurrentDirectory()}"); 41 | 42 | RunShell(cmd); 43 | 44 | Console.WriteLine("Zipping done! Uploading..."); 45 | 46 | var s3Client = new AmazonS3Client(); 47 | var response = await s3Client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest 48 | { 49 | BucketName = "lambci", 50 | Key = $"fs/{filename}", 51 | FilePath = $"/tmp/{filename}", 52 | CannedACL = S3CannedACL.PublicRead, 53 | }); 54 | 55 | Console.WriteLine("Uploading done!"); 56 | 57 | return response.HttpStatusCode.ToString(); 58 | } 59 | 60 | private static Process RunShell(string cmd) 61 | { 62 | var escapedArgs = cmd.Replace("\"", "\\\""); 63 | var process = new Process 64 | { 65 | StartInfo = new ProcessStartInfo 66 | { 67 | FileName = "/bin/sh", 68 | Arguments = $"-c \"{escapedArgs}\"", 69 | UseShellExecute = false, 70 | CreateNoWindow = true, 71 | } 72 | }; 73 | process.Start(); 74 | process.WaitForExit(); 75 | return process; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /base/dump-dotnetcore31/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "configuration": "Release", 3 | "framework": "netcoreapp3.1", 4 | "function-runtime": "dotnetcore3.1", 5 | "function-memory-size": 3008, 6 | "function-timeout": 60, 7 | "function-handler": "dump_dotnetcore31::dump_dotnetcore31.Function::FunctionHandler" 8 | } 9 | -------------------------------------------------------------------------------- /base/dump-dotnetcore31/dump-dotnetcore31.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | dump_dotnetcore31 6 | true 7 | dump_dotnetcore31 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /base/dump-go1x/dump-go1x.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "github.com/aws/aws-lambda-go/lambda" 7 | "github.com/aws/aws-sdk-go-v2/aws" 8 | "github.com/aws/aws-sdk-go-v2/aws/external" 9 | "github.com/aws/aws-sdk-go-v2/service/s3" 10 | "log" 11 | "os" 12 | "os/exec" 13 | ) 14 | 15 | func handleRequest(ctx context.Context, event interface{}) (*s3.PutObjectResponse, error) { 16 | filename := "go1.x.tgz" 17 | 18 | runShell("tar -cpzf /tmp/" + filename + " --numeric-owner --ignore-failed-read /var/runtime /var/lang") 19 | 20 | fmt.Println("Zipping done! Uploading...") 21 | 22 | cfg, err := external.LoadDefaultAWSConfig() 23 | if err != nil { 24 | log.Fatal(err) 25 | } 26 | 27 | file, err := os.Open("/tmp/" + filename) 28 | if err != nil { 29 | log.Fatal(err) 30 | } 31 | 32 | resp, err := s3.New(cfg).PutObjectRequest(&s3.PutObjectInput{ 33 | ACL: s3.ObjectCannedACLPublicRead, 34 | Body: file, 35 | Bucket: aws.String("lambci"), 36 | Key: aws.String("fs/" + filename), 37 | }).Send(context.Background()) 38 | if err != nil { 39 | log.Fatal(err) 40 | } 41 | 42 | fmt.Println("Uploading done!") 43 | 44 | runShell("ps aux") 45 | 46 | runShell("xargs --null --max-args=1 < /proc/1/environ") 47 | 48 | for _, a := range os.Args { 49 | fmt.Println(a) 50 | } 51 | pwd, _ := os.Getwd() 52 | fmt.Println(pwd) 53 | for _, e := range os.Environ() { 54 | fmt.Println(e) 55 | } 56 | fmt.Println(ctx) 57 | 58 | return resp, nil 59 | } 60 | 61 | func runShell(shellCmd string) { 62 | cmd := exec.Command("sh", "-c", shellCmd) 63 | cmd.Stdout = os.Stdout 64 | cmd.Stderr = os.Stderr 65 | cmd.Run() 66 | } 67 | 68 | func main() { 69 | lambda.Start(handleRequest) 70 | } 71 | 72 | /* 73 | PATH=/usr/local/bin:/usr/bin/:/bin:/opt/bin 74 | LANG=en_US.UTF-8 75 | TZ=:UTC 76 | LD_LIBRARY_PATH=/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib 77 | _LAMBDA_CONTROL_SOCKET=15 78 | _LAMBDA_CONSOLE_SOCKET=17 79 | LAMBDA_TASK_ROOT=/var/task 80 | LAMBDA_RUNTIME_DIR=/var/runtime 81 | _LAMBDA_LOG_FD=24 82 | _LAMBDA_SB_ID=8 83 | _LAMBDA_SHARED_MEM_FD=12 84 | AWS_REGION=us-east-1 85 | AWS_DEFAULT_REGION=us-east-1 86 | AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/dump-go1x 87 | AWS_LAMBDA_LOG_STREAM_NAME=2018/01/16/[$LATEST]12d47417179844e3ad55190a93a817d7 88 | AWS_LAMBDA_FUNCTION_NAME=dump-go1x 89 | AWS_LAMBDA_FUNCTION_MEMORY_SIZE=3008 90 | AWS_LAMBDA_FUNCTION_VERSION=$LATEST 91 | _AWS_XRAY_DAEMON_ADDRESS=169.254.79.2 92 | _AWS_XRAY_DAEMON_PORT=2000 93 | AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000 94 | AWS_XRAY_CONTEXT_MISSING=LOG_ERROR 95 | _X_AMZN_TRACE_ID=Parent=41bc1aa71e1174a5 96 | _HANDLER=my_handler 97 | _LAMBDA_RUNTIME_LOAD_TIME=1522376103407 98 | 99 | /var/task 100 | /var/task/my_handler 101 | 102 | PATH=/usr/local/bin:/usr/bin/:/bin:/opt/bin 103 | LANG=en_US.UTF-8 104 | TZ=:UTC 105 | LD_LIBRARY_PATH=/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib 106 | _LAMBDA_CONTROL_SOCKET=15 107 | _LAMBDA_CONSOLE_SOCKET=17 108 | LAMBDA_TASK_ROOT=/var/task 109 | LAMBDA_RUNTIME_DIR=/var/runtime 110 | _LAMBDA_LOG_FD=24 111 | _LAMBDA_SB_ID=8 112 | _LAMBDA_SHARED_MEM_FD=12 113 | AWS_REGION=us-east-1 114 | AWS_DEFAULT_REGION=us-east-1 115 | AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/dump-go1x 116 | AWS_LAMBDA_LOG_STREAM_NAME=2018/01/16/[$LATEST]12d47417179844e3ad55190a93a817d7 117 | AWS_LAMBDA_FUNCTION_NAME=dump-go1x 118 | AWS_LAMBDA_FUNCTION_MEMORY_SIZE=3008 119 | AWS_LAMBDA_FUNCTION_VERSION=$LATEST 120 | _AWS_XRAY_DAEMON_ADDRESS=169.254.79.2 121 | _AWS_XRAY_DAEMON_PORT=2000 122 | AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000 123 | AWS_XRAY_CONTEXT_MISSING=LOG_ERROR 124 | _X_AMZN_TRACE_ID=Parent=41bc1aa71e1174a5 125 | _HANDLER=my_handler 126 | _LAMBDA_RUNTIME_LOAD_TIME=1522376103407 127 | 128 | _LAMBDA_SERVER_PORT=60304 129 | AWS_ACCESS_KEY= 130 | AWS_ACCESS_KEY_ID= 131 | AWS_SECRET_KEY= 132 | AWS_SECRET_ACCESS_KEY= 133 | AWS_SESSION_TOKEN= 134 | AWS_SECURITY_TOKEN= 135 | 136 | context.Background.WithDeadline(2018-01-12 21:16:44.121702432 +0000 UTC [2.981503691s]).WithValue( 137 | &lambdacontext.key{}, 138 | &lambdacontext.LambdaContext{ 139 | AwsRequestID:"e1e762a8-f7dd-11e7-8572-1dc9a2c870b7", 140 | InvokedFunctionArn:"arn:aws:lambda:us-east-1:XXXXXXXXXXXX:function:dump-go1x", 141 | Identity:lambdacontext.CognitoIdentity{CognitoIdentityID:"", CognitoIdentityPoolID:""}, 142 | ClientContext:lambdacontext.ClientContext{Client:lambdacontext.ClientApplication{InstallationID:"", AppTitle:"", AppVersionCode:"", AppPackageName:""}, 143 | Env:map[string]string(nil), 144 | Custom:map[string]string(nil)} 145 | }).WithValue("x-amzn-trace-id", "Root=1-5a5925b8-30ae34971b99966e26b15b1e;Parent=06346dc778d0afed;Sampled=1") 146 | */ 147 | -------------------------------------------------------------------------------- /base/dump-go1x/go.mod: -------------------------------------------------------------------------------- 1 | module dump-go1x 2 | 3 | require ( 4 | github.com/aws/aws-lambda-go v1.13.3 5 | github.com/aws/aws-sdk-go-v2 v0.17.0 6 | ) 7 | 8 | go 1.15 9 | -------------------------------------------------------------------------------- /base/dump-go1x/go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/aws/aws-lambda-go v1.13.2 h1:8lYuRVn6rESoUNZXdbCmtGB4bBk4vcVYojiHjE4mMrM= 3 | github.com/aws/aws-lambda-go v1.13.2/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= 4 | github.com/aws/aws-lambda-go v1.13.3 h1:SuCy7H3NLyp+1Mrfp+m80jcbi9KYWAs9/BXwppwRDzY= 5 | github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= 6 | github.com/aws/aws-sdk-go-v2 v0.16.0 h1:X5pkFnjRNdDEX18NwDGWMaWL5ocNQX0qIYEhEcsTy64= 7 | github.com/aws/aws-sdk-go-v2 v0.16.0/go.mod h1:pFLIN9LDjOEwHfruGweAXEq0XaD6uRkY8FsRkxhuBIg= 8 | github.com/aws/aws-sdk-go-v2 v0.17.0 h1:b/9gp0SD6doAWv72f3ZwzFJSsWmUw9dM8wMNmf6OBws= 9 | github.com/aws/aws-sdk-go-v2 v0.17.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= 10 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= 14 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 15 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 16 | github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= 17 | github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= 18 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 19 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 20 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 21 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 22 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 23 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 24 | github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 25 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 26 | golang.org/x/net v0.0.0-20181201002055-351d144fa1fc h1:a3CU5tJYVj92DY2LaA1kUkrsqD5/3mLDhx2NcNqyW+0= 27 | golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 28 | golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 29 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 30 | google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 31 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 32 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 33 | -------------------------------------------------------------------------------- /base/dump-java11/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /base/dump-java11/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | dump-java11 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | 25 | 1599680497019 26 | 27 | 30 28 | 29 | org.eclipse.core.resources.regexFilterMatcher 30 | node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /base/dump-java11/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | arguments= 2 | auto.sync=false 3 | build.scans.enabled=false 4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0-20191016123526+0000)) 5 | connection.project.dir= 6 | eclipse.preferences.version=1 7 | gradle.user.home= 8 | java.home= 9 | jvm.arguments= 10 | offline.mode=false 11 | override.workspace.settings=true 12 | show.console.view=true 13 | show.executions.view=true 14 | -------------------------------------------------------------------------------- /base/dump-java11/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 3 | org.eclipse.jdt.core.compiler.compliance=11 4 | org.eclipse.jdt.core.compiler.source=11 5 | -------------------------------------------------------------------------------- /base/dump-java11/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | sourceCompatibility = '11' 4 | targetCompatibility = '11' 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | implementation ( 12 | 'com.amazonaws:aws-lambda-java-core:1.2.0', 13 | 'com.amazonaws:aws-lambda-java-events:2.2.7', 14 | 'com.amazonaws:aws-java-sdk-s3:1.11.681' 15 | ) 16 | } 17 | 18 | task buildZip(type: Zip) { 19 | from compileJava 20 | from processResources 21 | into('lib') { 22 | from configurations.runtimeClasspath 23 | } 24 | } 25 | 26 | build.dependsOn buildZip 27 | 28 | // docker run --rm -v "$PWD":/app -w /app gradle:jdk11 gradle build 29 | -------------------------------------------------------------------------------- /base/dump-java11/src/main/java/org/lambci/lambda/DumpJava11.java: -------------------------------------------------------------------------------- 1 | package org.lambci.lambda; 2 | 3 | import java.io.File; 4 | import java.lang.management.ManagementFactory; 5 | import java.util.Map; 6 | import java.util.Scanner; 7 | 8 | import com.amazonaws.services.lambda.runtime.Context; 9 | import com.amazonaws.services.lambda.runtime.RequestHandler; 10 | import com.amazonaws.services.s3.AmazonS3; 11 | import com.amazonaws.services.s3.AmazonS3ClientBuilder; 12 | import com.amazonaws.services.s3.model.CannedAccessControlList; 13 | import com.amazonaws.services.s3.model.PutObjectRequest; 14 | import com.amazonaws.services.s3.model.PutObjectResult; 15 | 16 | public class DumpJava11 implements RequestHandler { 17 | 18 | @Override 19 | public PutObjectResult handleRequest(Object input, Context context) { 20 | String filename = "java11.tgz"; 21 | String cmd = "tar -cpzf /tmp/" + filename + " --numeric-owner --ignore-failed-read /var/runtime /var/lang"; 22 | AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion("us-east-1").build(); 23 | 24 | System.out.println(ManagementFactory.getRuntimeMXBean().getInputArguments().toString()); 25 | System.out.println(System.getProperty("sun.java.command")); 26 | System.out.println(System.getProperty("java.home")); 27 | System.out.println(System.getProperty("java.library.path")); 28 | System.out.println(System.getProperty("java.class.path")); 29 | System.out.println(System.getProperty("user.dir")); 30 | System.out.println(System.getProperty("user.home")); 31 | System.out.println(System.getProperty("user.name")); 32 | System.out.println(new File(".").getAbsolutePath()); 33 | Map env = System.getenv(); 34 | for (String envName : env.keySet()) { 35 | System.out.println(envName + "=" + env.get(envName)); 36 | } 37 | 38 | try { 39 | Process process = Runtime.getRuntime().exec(new String[] { "sh", "-c", cmd }); 40 | 41 | try (Scanner stdoutScanner = new Scanner(process.getInputStream()); 42 | Scanner stderrScanner = new Scanner(process.getErrorStream())) { 43 | // Echo all stdout first 44 | while (stdoutScanner.hasNextLine()) { 45 | System.out.println(stdoutScanner.nextLine()); 46 | } 47 | // Then echo stderr 48 | while (stderrScanner.hasNextLine()) { 49 | System.err.println(stderrScanner.nextLine()); 50 | } 51 | } 52 | 53 | process.waitFor(); 54 | if (process.exitValue() != 0) { 55 | return null; 56 | } 57 | 58 | System.out.println("Zipping done! Uploading..."); 59 | 60 | return s3client.putObject(new PutObjectRequest("lambci", "fs/" + filename, new File("/tmp/" + filename)) 61 | .withCannedAcl(CannedAccessControlList.PublicRead)); 62 | } catch (Exception e) { 63 | throw new RuntimeException(e); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /base/dump-java8/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /base/dump-java8/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | dump-java8 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | 25 | 1599680497033 26 | 27 | 30 28 | 29 | org.eclipse.core.resources.regexFilterMatcher 30 | node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /base/dump-java8/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | arguments= 2 | auto.sync=false 3 | build.scans.enabled=false 4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3)) 5 | connection.project.dir= 6 | eclipse.preferences.version=1 7 | gradle.user.home= 8 | java.home= 9 | jvm.arguments= 10 | offline.mode=false 11 | override.workspace.settings=true 12 | show.console.view=true 13 | show.executions.view=true 14 | -------------------------------------------------------------------------------- /base/dump-java8/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | -------------------------------------------------------------------------------- /base/dump-java8/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /base/dump-java8/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | sourceCompatibility = '1.8' 4 | targetCompatibility = '1.8' 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | implementation ( 12 | 'com.amazonaws:aws-lambda-java-core:1.2.0', 13 | 'com.amazonaws:aws-lambda-java-events:2.2.7', 14 | 'com.amazonaws:aws-java-sdk-s3:1.11.681' 15 | ) 16 | } 17 | 18 | task buildZip(type: Zip) { 19 | from compileJava 20 | from processResources 21 | into('lib') { 22 | from configurations.runtimeClasspath 23 | } 24 | } 25 | 26 | build.dependsOn buildZip 27 | 28 | // docker run --rm -v "$PWD":/app -w /app gradle:jdk8 gradle build 29 | -------------------------------------------------------------------------------- /base/dump-java8/src/main/java/org/lambci/lambda/DumpJava8.java: -------------------------------------------------------------------------------- 1 | package org.lambci.lambda; 2 | 3 | import java.io.File; 4 | import java.lang.management.ManagementFactory; 5 | import java.util.Map; 6 | import java.util.Scanner; 7 | 8 | import com.amazonaws.services.lambda.runtime.Context; 9 | import com.amazonaws.services.lambda.runtime.RequestHandler; 10 | import com.amazonaws.services.s3.AmazonS3; 11 | import com.amazonaws.services.s3.AmazonS3ClientBuilder; 12 | import com.amazonaws.services.s3.model.CannedAccessControlList; 13 | import com.amazonaws.services.s3.model.PutObjectRequest; 14 | import com.amazonaws.services.s3.model.PutObjectResult; 15 | 16 | public class DumpJava8 implements RequestHandler { 17 | 18 | @Override 19 | public PutObjectResult handleRequest(Object input, Context context) { 20 | String filename = "java8.tgz"; 21 | String cmd = "tar -cpzf /tmp/" + filename + " --numeric-owner --ignore-failed-read /var/runtime /var/lang"; 22 | AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion("us-east-1").build(); 23 | 24 | System.out.println(ManagementFactory.getRuntimeMXBean().getInputArguments().toString()); 25 | System.out.println(System.getProperty("sun.java.command")); 26 | System.out.println(System.getProperty("java.home")); 27 | System.out.println(System.getProperty("java.library.path")); 28 | System.out.println(System.getProperty("java.class.path")); 29 | System.out.println(System.getProperty("user.dir")); 30 | System.out.println(System.getProperty("user.home")); 31 | System.out.println(System.getProperty("user.name")); 32 | System.out.println(new File(".").getAbsolutePath()); 33 | Map env = System.getenv(); 34 | for (String envName : env.keySet()) { 35 | System.out.println(envName + "=" + env.get(envName)); 36 | } 37 | 38 | try { 39 | Process process = Runtime.getRuntime().exec(new String[] { "sh", "-c", cmd }); 40 | 41 | try (Scanner stdoutScanner = new Scanner(process.getInputStream()); 42 | Scanner stderrScanner = new Scanner(process.getErrorStream())) { 43 | // Echo all stdout first 44 | while (stdoutScanner.hasNextLine()) { 45 | System.out.println(stdoutScanner.nextLine()); 46 | } 47 | // Then echo stderr 48 | while (stderrScanner.hasNextLine()) { 49 | System.err.println(stderrScanner.nextLine()); 50 | } 51 | } 52 | 53 | process.waitFor(); 54 | if (process.exitValue() != 0) { 55 | return null; 56 | } 57 | 58 | System.out.println("Zipping done! Uploading..."); 59 | 60 | return s3client.putObject(new PutObjectRequest("lambci", "fs/" + filename, new File("/tmp/" + filename)) 61 | .withCannedAcl(CannedAccessControlList.PublicRead)); 62 | } catch (Exception e) { 63 | throw new RuntimeException(e); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /base/dump-java8al2/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /base/dump-java8al2/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | dump-java8 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | 25 | 1599680497040 26 | 27 | 30 28 | 29 | org.eclipse.core.resources.regexFilterMatcher 30 | node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /base/dump-java8al2/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | arguments= 2 | auto.sync=false 3 | build.scans.enabled=false 4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3)) 5 | connection.project.dir= 6 | eclipse.preferences.version=1 7 | gradle.user.home= 8 | java.home= 9 | jvm.arguments= 10 | offline.mode=false 11 | override.workspace.settings=true 12 | show.console.view=true 13 | show.executions.view=true 14 | -------------------------------------------------------------------------------- /base/dump-java8al2/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | -------------------------------------------------------------------------------- /base/dump-java8al2/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /base/dump-java8al2/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | sourceCompatibility = '1.8' 4 | targetCompatibility = '1.8' 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | implementation ( 12 | 'com.amazonaws:aws-lambda-java-core:1.2.0', 13 | 'com.amazonaws:aws-lambda-java-events:2.2.7', 14 | 'com.amazonaws:aws-java-sdk-s3:1.11.681' 15 | ) 16 | } 17 | 18 | task buildZip(type: Zip) { 19 | from compileJava 20 | from processResources 21 | into('lib') { 22 | from configurations.runtimeClasspath 23 | } 24 | } 25 | 26 | build.dependsOn buildZip 27 | 28 | // docker run --rm -v "$PWD":/app -w /app gradle:jdk8 gradle build 29 | -------------------------------------------------------------------------------- /base/dump-java8al2/src/main/java/org/lambci/lambda/DumpJava8.java: -------------------------------------------------------------------------------- 1 | package org.lambci.lambda; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.lang.InterruptedException; 6 | import java.lang.management.ManagementFactory; 7 | import java.nio.file.Files; 8 | import java.nio.file.Paths; 9 | import java.util.Map; 10 | import java.util.Scanner; 11 | 12 | import com.amazonaws.services.lambda.runtime.Context; 13 | import com.amazonaws.services.lambda.runtime.RequestHandler; 14 | import com.amazonaws.services.s3.AmazonS3; 15 | import com.amazonaws.services.s3.AmazonS3ClientBuilder; 16 | import com.amazonaws.services.s3.model.CannedAccessControlList; 17 | import com.amazonaws.services.s3.model.PutObjectRequest; 18 | import com.amazonaws.services.s3.model.PutObjectResult; 19 | 20 | public class DumpJava8 implements RequestHandler { 21 | 22 | @Override 23 | public PutObjectResult handleRequest(Object input, Context context) { 24 | String filename = "java8.al2.tgz"; 25 | String cmd = "tar -cpzf /tmp/" + filename + " --numeric-owner --ignore-failed-read /var/runtime /var/lang"; 26 | AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion("us-east-1").build(); 27 | 28 | System.out.println(ManagementFactory.getRuntimeMXBean().getInputArguments().toString()); 29 | System.out.println(System.getProperty("sun.java.command")); 30 | System.out.println(System.getProperty("java.home")); 31 | System.out.println(System.getProperty("java.library.path")); 32 | System.out.println(System.getProperty("java.class.path")); 33 | System.out.println(System.getProperty("user.dir")); 34 | System.out.println(System.getProperty("user.home")); 35 | System.out.println(System.getProperty("user.name")); 36 | System.out.println(new File(".").getAbsolutePath()); 37 | Map env = System.getenv(); 38 | for (String envName : env.keySet()) { 39 | System.out.println(envName + "=" + env.get(envName)); 40 | } 41 | 42 | try { 43 | int pid = Integer.parseInt(new File("/proc/self").getCanonicalFile().getName()); 44 | 45 | System.out.println("Parent cmdline:"); 46 | System.out.println(new String(Files.readAllBytes(Paths.get("/proc/1/cmdline"))).replace("\0", " ")); 47 | 48 | System.out.println("Parent env:"); 49 | runShell("xargs --null --max-args=1 < /proc/1/environ"); 50 | 51 | System.out.println("This cmdline:"); 52 | System.out.println(new String(Files.readAllBytes(Paths.get("/proc/" + pid + "/cmdline"))).replace("\0", " ")); 53 | 54 | System.out.println("This env:"); 55 | runShell("xargs --null --max-args=1 < /proc/" + pid + "/environ"); 56 | 57 | if (runShell(cmd) != 0) { 58 | return null; 59 | } 60 | 61 | System.out.println("Zipping done! Uploading..."); 62 | 63 | return s3client.putObject(new PutObjectRequest("lambci", "fs/" + filename, new File("/tmp/" + filename)) 64 | .withCannedAcl(CannedAccessControlList.PublicRead)); 65 | } catch (Exception e) { 66 | throw new RuntimeException(e); 67 | } 68 | } 69 | 70 | public static int runShell(String cmd) throws IOException, InterruptedException { 71 | Process process = Runtime.getRuntime().exec(new String[] { "sh", "-c", cmd }); 72 | 73 | try (Scanner stdoutScanner = new Scanner(process.getInputStream()); 74 | Scanner stderrScanner = new Scanner(process.getErrorStream())) { 75 | // Echo all stdout first 76 | while (stdoutScanner.hasNextLine()) { 77 | System.out.println(stdoutScanner.nextLine()); 78 | } 79 | // Then echo stderr 80 | while (stderrScanner.hasNextLine()) { 81 | System.err.println(stderrScanner.nextLine()); 82 | } 83 | } 84 | 85 | process.waitFor(); 86 | return process.exitValue(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /base/dump-node10x.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const { execSync } = require('child_process') 3 | const AWS = require('aws-sdk') 4 | const s3 = new AWS.S3() 5 | 6 | // Depends on tar-find-layer for the tar/find/xargs binaries 7 | exports.handler = async(event, context) => { 8 | const execOpts = { stdio: 'inherit', maxBuffer: 16 * 1024 * 1024 } 9 | 10 | let filename = 'base-2.tgz' 11 | let cmd = 'tar -cpzf /tmp/' + filename + 12 | ' -C / --exclude=/proc --exclude=/sys --exclude=/dev --exclude=/tmp ' + 13 | '--exclude=/var/task/* --exclude=/var/runtime/* --exclude=/var/lang/* --exclude=/var/rapid/* --exclude=/opt/* ' + 14 | '--numeric-owner --ignore-failed-read /' 15 | 16 | execSync(event.cmd || cmd, execOpts) 17 | if (event.cmd) return 18 | 19 | console.log('Zipping done! Uploading...') 20 | 21 | let data = await s3.upload({ 22 | Bucket: 'lambci', 23 | Key: 'fs/' + filename, 24 | Body: fs.createReadStream('/tmp/' + filename), 25 | ACL: 'public-read', 26 | }).promise() 27 | 28 | filename = 'nodejs10.x.tgz' 29 | cmd = 'tar -cpzf /tmp/' + filename + 30 | ' --numeric-owner --ignore-failed-read /var/runtime /var/lang /var/rapid' 31 | 32 | execSync(cmd, execOpts) 33 | 34 | console.log('Zipping done! Uploading...') 35 | 36 | data = await s3.upload({ 37 | Bucket: 'lambci', 38 | Key: 'fs/' + filename, 39 | Body: fs.createReadStream('/tmp/' + filename), 40 | ACL: 'public-read', 41 | }).promise() 42 | 43 | console.log('Uploading done!') 44 | 45 | console.log(process.execPath) 46 | console.log(process.execArgv) 47 | console.log(process.argv) 48 | console.log(process.cwd()) 49 | console.log(__filename) 50 | console.log(process.env) 51 | execSync('echo /proc/1/environ; xargs -n 1 -0 < /proc/1/environ', execOpts) 52 | execSync("bash -O extglob -c 'for cmd in /proc/+([0-9])/cmdline; do echo $cmd; xargs -n 1 -0 < $cmd; done'", execOpts) 53 | console.log(context) 54 | 55 | return data 56 | } 57 | -------------------------------------------------------------------------------- /base/dump-node12x.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const { execSync } = require('child_process') 3 | const AWS = require('aws-sdk') 4 | const s3 = new AWS.S3() 5 | 6 | // Depends on tar-find-layer for the tar/find/xargs binaries 7 | exports.handler = async(event, context) => { 8 | const execOpts = { stdio: 'inherit', maxBuffer: 16 * 1024 * 1024 } 9 | 10 | let filename = 'nodejs12.x.tgz' 11 | let cmd = 'tar -cpzf /tmp/' + filename + 12 | ' --numeric-owner --ignore-failed-read /var/runtime /var/lang /var/rapid' 13 | 14 | execSync(cmd, execOpts) 15 | 16 | console.log('Zipping done! Uploading...') 17 | 18 | let data = await s3.upload({ 19 | Bucket: 'lambci', 20 | Key: 'fs/' + filename, 21 | Body: fs.createReadStream('/tmp/' + filename), 22 | ACL: 'public-read', 23 | }).promise() 24 | 25 | console.log('Uploading done!') 26 | 27 | console.log(process.execPath) 28 | console.log(process.execArgv) 29 | console.log(process.argv) 30 | console.log(process.cwd()) 31 | console.log(__filename) 32 | console.log(process.env) 33 | execSync('echo /proc/1/environ; xargs -n 1 -0 < /proc/1/environ', execOpts) 34 | execSync("bash -O extglob -c 'for cmd in /proc/+([0-9])/cmdline; do echo $cmd; xargs -n 1 -0 < $cmd; done'", execOpts) 35 | console.log(context) 36 | 37 | return data 38 | } 39 | -------------------------------------------------------------------------------- /base/dump-nodejs.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | var childProcess = require('child_process') 3 | var AWS = require('aws-sdk') 4 | var s3 = new AWS.S3() 5 | 6 | exports.handler = function(event, context) { 7 | var filename = 'nodejs.tgz' 8 | var cmd = 'tar -cpzf /tmp/' + filename + 9 | ' --numeric-owner --ignore-failed-read /var/runtime /var/lang' 10 | 11 | var child = childProcess.spawn('sh', ['-c', event.cmd || cmd]) 12 | child.stdout.setEncoding('utf8') 13 | child.stderr.setEncoding('utf8') 14 | child.stdout.on('data', console.log.bind(console)) 15 | child.stderr.on('data', console.error.bind(console)) 16 | child.on('error', context.done.bind(context)) 17 | 18 | child.on('close', function() { 19 | if (event.cmd) return context.done() 20 | 21 | console.log('Zipping done! Uploading...') 22 | 23 | s3.upload({ 24 | Bucket: 'lambci', 25 | Key: 'fs/' + filename, 26 | Body: fs.createReadStream('/tmp/' + filename), 27 | ACL: 'public-read', 28 | }, function(err, data) { 29 | if (err) return context.done(err) 30 | 31 | console.log('Uploading done!') 32 | 33 | console.log(process.execPath) 34 | console.log(process.execArgv) 35 | console.log(process.argv) 36 | console.log(process.cwd()) 37 | console.log(__filename) 38 | console.log(process.env) 39 | console.log(context) 40 | 41 | context.done() 42 | }) 43 | }) 44 | } 45 | 46 | // /usr/bin/node 47 | // [ '--max-old-space-size=1229', '--max-new-space-size=153', '--max-executable-size=153', '--expose-gc' ] 48 | // [ '/usr/bin/node', '/var/runtime/node_modules/awslambda/bin/awslambda' ] 49 | // /var/task 50 | // /var/task/index.js 51 | // { 52 | // PATH: '/usr/local/bin:/usr/bin/:/bin:/opt/bin', 53 | // LANG: 'en_US.UTF-8', 54 | // LD_LIBRARY_PATH: '/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib', 55 | // LAMBDA_TASK_ROOT: '/var/task', 56 | // LAMBDA_RUNTIME_DIR: '/var/runtime', 57 | // AWS_REGION: 'us-east-1', 58 | // AWS_DEFAULT_REGION: 'us-east-1', 59 | // AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/dump-node010', 60 | // AWS_LAMBDA_LOG_STREAM_NAME: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f', 61 | // AWS_LAMBDA_FUNCTION_NAME: 'dump-node010', 62 | // AWS_LAMBDA_FUNCTION_MEMORY_SIZE: '1536', 63 | // AWS_LAMBDA_FUNCTION_VERSION: '$LATEST', 64 | // _AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2', 65 | // _AWS_XRAY_DAEMON_PORT: '2000', 66 | // AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2:2000', 67 | // AWS_XRAY_CONTEXT_MISSING: 'LOG_ERROR', 68 | // _X_AMZN_TRACE_ID: 'Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=0', 69 | // AWS_EXECUTION_ENV: 'AWS_Lambda_nodejs', 70 | // NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules', 71 | // AWS_ACCESS_KEY_ID: 'ASIA...C37A', 72 | // AWS_SECRET_ACCESS_KEY: 'JZvD...BDZ4L', 73 | // AWS_SESSION_TOKEN: 'FQoDYXdzEMb//////////...0oog7bzuQU=' 74 | // } 75 | // { 76 | // awsRequestId: '1fcdc383-a9e8-4228-bc1c-8db17629e183', 77 | // invokeid: '1fcdc383-a9e8-4228-bc1c-8db17629e183', 78 | // logGroupName: '/aws/lambda/dump-node010', 79 | // logStreamName: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f', 80 | // functionName: 'dump-node010', 81 | // memoryLimitInMB: '1536', 82 | // functionVersion: '$LATEST', 83 | // invokedFunctionArn: 'arn:aws:lambda:us-east-1:879423879432:function:dump-node010', 84 | // getRemainingTimeInMillis: [Function], 85 | // succeed: [Function], 86 | // fail: [Function], 87 | // done: [Function] 88 | // } 89 | -------------------------------------------------------------------------------- /base/dump-nodejs43.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | var childProcess = require('child_process') 3 | var AWS = require('aws-sdk') 4 | var s3 = new AWS.S3() 5 | 6 | exports.handler = function(event, context, cb) { 7 | var filename = 'nodejs4.3.tgz' 8 | var cmd = 'tar -cpzf /tmp/' + filename + 9 | ' --numeric-owner --ignore-failed-read /var/runtime /var/lang' 10 | 11 | var child = childProcess.spawn('sh', ['-c', event.cmd || cmd]) 12 | child.stdout.setEncoding('utf8') 13 | child.stderr.setEncoding('utf8') 14 | child.stdout.on('data', console.log.bind(console)) 15 | child.stderr.on('data', console.error.bind(console)) 16 | child.on('error', cb) 17 | 18 | child.on('close', function() { 19 | if (event.cmd) return cb() 20 | 21 | console.log('Zipping done! Uploading...') 22 | 23 | s3.upload({ 24 | Bucket: 'lambci', 25 | Key: 'fs/' + filename, 26 | Body: fs.createReadStream('/tmp/' + filename), 27 | ACL: 'public-read', 28 | }, function(err, data) { 29 | if (err) return cb(err) 30 | 31 | console.log('Uploading done!') 32 | 33 | console.log(process.execPath) 34 | console.log(process.execArgv) 35 | console.log(process.argv) 36 | console.log(process.cwd()) 37 | console.log(__filename) 38 | console.log(process.env) 39 | console.log(childProcess.execSync('xargs -n 1 -0 < /proc/1/environ', { encoding: 'utf8' })) 40 | console.log(childProcess.execSync('ps aux', { encoding: 'utf8' })) 41 | console.log(context) 42 | 43 | cb(null, data) 44 | }) 45 | }) 46 | } 47 | 48 | // /var/lang/bin/node 49 | // [ '--max-old-space-size=2547', '--max-semi-space-size=150', '--max-executable-size=160', '--expose-gc' ] 50 | // [ '/var/lang/bin/node', '/var/runtime/node_modules/awslambda/index.js' ] 51 | // /var/task 52 | // /var/task/index.js 53 | // { 54 | // PATH: '/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin', 55 | // LANG: 'en_US.UTF-8', 56 | // LD_LIBRARY_PATH: '/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib', 57 | // LAMBDA_TASK_ROOT: '/var/task', 58 | // LAMBDA_RUNTIME_DIR: '/var/runtime', 59 | // AWS_REGION: 'us-east-1', 60 | // AWS_DEFAULT_REGION: 'us-east-1', 61 | // AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/dump-node43', 62 | // AWS_LAMBDA_LOG_STREAM_NAME: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f', 63 | // AWS_LAMBDA_FUNCTION_NAME: 'dump-node43', 64 | // AWS_LAMBDA_FUNCTION_MEMORY_SIZE: '1536', 65 | // AWS_LAMBDA_FUNCTION_VERSION: '$LATEST', 66 | // _AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2', 67 | // _AWS_XRAY_DAEMON_PORT: '2000', 68 | // AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2:2000', 69 | // AWS_XRAY_CONTEXT_MISSING: 'LOG_ERROR', 70 | // _X_AMZN_TRACE_ID: 'Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=0', 71 | // AWS_EXECUTION_ENV: 'AWS_Lambda_nodejs4.3', 72 | // NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules', 73 | // AWS_ACCESS_KEY_ID: 'ASIA...C37A', 74 | // AWS_SECRET_ACCESS_KEY: 'JZvD...BDZ4L', 75 | // AWS_SESSION_TOKEN: 'FQoDYXdzEMb//////////...0oog7bzuQU=' 76 | // } 77 | // { 78 | // callbackWaitsForEmptyEventLoop: [Getter/Setter], 79 | // done: [Function], 80 | // succeed: [Function], 81 | // fail: [Function], 82 | // logGroupName: '/aws/lambda/dump-node43', 83 | // logStreamName: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f', 84 | // functionName: 'dump-node43', 85 | // memoryLimitInMB: '1536', 86 | // functionVersion: '$LATEST', 87 | // getRemainingTimeInMillis: [Function], 88 | // invokeid: '1fcdc383-a9e8-4228-bc1c-8db17629e183', 89 | // awsRequestId: '1fcdc383-a9e8-4228-bc1c-8db17629e183', 90 | // invokedFunctionArn: 'arn:aws:lambda:us-east-1:879423879432:function:dump-node43' 91 | // } 92 | -------------------------------------------------------------------------------- /base/dump-nodejs610.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | var childProcess = require('child_process') 3 | var AWS = require('aws-sdk') 4 | var s3 = new AWS.S3() 5 | 6 | exports.handler = function(event, context, cb) { 7 | var filename = 'nodejs6.10.tgz' 8 | var cmd = 'tar -cpzf /tmp/' + filename + 9 | ' --numeric-owner --ignore-failed-read /var/runtime /var/lang' 10 | 11 | var child = childProcess.spawn('sh', ['-c', event.cmd || cmd]) 12 | child.stdout.setEncoding('utf8') 13 | child.stderr.setEncoding('utf8') 14 | child.stdout.on('data', console.log.bind(console)) 15 | child.stderr.on('data', console.error.bind(console)) 16 | child.on('error', cb) 17 | 18 | child.on('close', function() { 19 | if (event.cmd) return cb() 20 | 21 | console.log('Zipping done! Uploading...') 22 | 23 | s3.upload({ 24 | Bucket: 'lambci', 25 | Key: 'fs/' + filename, 26 | Body: fs.createReadStream('/tmp/' + filename), 27 | ACL: 'public-read', 28 | }, function(err, data) { 29 | if (err) return cb(err) 30 | 31 | console.log('Uploading done!') 32 | 33 | console.log(process.execPath) 34 | console.log(process.execArgv) 35 | console.log(process.argv) 36 | console.log(process.cwd()) 37 | console.log(__filename) 38 | console.log(process.env) 39 | console.log(childProcess.execSync('xargs -n 1 -0 < /proc/1/environ', { encoding: 'utf8' })) 40 | console.log(childProcess.execSync('ps aux', { encoding: 'utf8' })) 41 | console.log(context) 42 | 43 | cb(null, data) 44 | }) 45 | }) 46 | } 47 | 48 | // /var/lang/bin/node 49 | // [ '--max-old-space-size=1229', '--max-semi-space-size=76', '--max-executable-size=153', '--expose-gc' ] 50 | // [ '/var/lang/bin/node', '/var/runtime/node_modules/awslambda/index.js' ] 51 | // /var/task 52 | // /var/task/index.js 53 | // { 54 | // PATH: '/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin', 55 | // LANG: 'en_US.UTF-8', 56 | // LD_LIBRARY_PATH: '/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib', 57 | // LAMBDA_TASK_ROOT: '/var/task', 58 | // LAMBDA_RUNTIME_DIR: '/var/runtime', 59 | // AWS_REGION: 'us-east-1', 60 | // AWS_DEFAULT_REGION: 'us-east-1', 61 | // AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/dump-node610', 62 | // AWS_LAMBDA_LOG_STREAM_NAME: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f', 63 | // AWS_LAMBDA_FUNCTION_NAME: 'dump-node610', 64 | // AWS_LAMBDA_FUNCTION_MEMORY_SIZE: '1536', 65 | // AWS_LAMBDA_FUNCTION_VERSION: '$LATEST', 66 | // _AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2', 67 | // _AWS_XRAY_DAEMON_PORT: '2000', 68 | // AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2:2000', 69 | // AWS_XRAY_CONTEXT_MISSING: 'LOG_ERROR', 70 | // _X_AMZN_TRACE_ID: 'Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=0', 71 | // AWS_EXECUTION_ENV: 'AWS_Lambda_nodejs6.10', 72 | // NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules', 73 | // AWS_ACCESS_KEY_ID: 'ASIA...C37A', 74 | // AWS_SECRET_ACCESS_KEY: 'JZvD...BDZ4L', 75 | // AWS_SESSION_TOKEN: 'FQoDYXdzEMb//////////...0oog7bzuQU=' 76 | // } 77 | // { 78 | // callbackWaitsForEmptyEventLoop: [Getter/Setter], 79 | // done: [Function: done], 80 | // succeed: [Function: succeed], 81 | // fail: [Function: fail], 82 | // logGroupName: '/aws/lambda/dump-node610', 83 | // logStreamName: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f', 84 | // functionName: 'dump-node610', 85 | // memoryLimitInMB: '1536', 86 | // functionVersion: '$LATEST', 87 | // getRemainingTimeInMillis: [Function: getRemainingTimeInMillis], 88 | // invokeid: '1fcdc383-a9e8-4228-bc1c-8db17629e183', 89 | // awsRequestId: '1fcdc383-a9e8-4228-bc1c-8db17629e183', 90 | // invokedFunctionArn: 'arn:aws:lambda:us-east-1:879423879432:function:dump-node610' 91 | // } 92 | -------------------------------------------------------------------------------- /base/dump-nodejs810.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | var childProcess = require('child_process') 3 | var AWS = require('aws-sdk') 4 | var s3 = new AWS.S3() 5 | 6 | exports.handler = function(event, context, cb) { 7 | var filename = 'nodejs8.10.tgz' 8 | var cmd = 'tar -cpzf /tmp/' + filename + 9 | ' --numeric-owner --ignore-failed-read /var/runtime /var/lang' 10 | 11 | var child = childProcess.spawn('sh', ['-c', event.cmd || cmd]) 12 | child.stdout.setEncoding('utf8') 13 | child.stderr.setEncoding('utf8') 14 | child.stdout.on('data', console.log.bind(console)) 15 | child.stderr.on('data', console.error.bind(console)) 16 | child.on('error', cb) 17 | 18 | child.on('close', function() { 19 | if (event.cmd) return cb() 20 | 21 | console.log('Zipping done! Uploading...') 22 | 23 | s3.upload({ 24 | Bucket: 'lambci', 25 | Key: 'fs/' + filename, 26 | Body: fs.createReadStream('/tmp/' + filename), 27 | ACL: 'public-read', 28 | }, function(err, data) { 29 | if (err) return cb(err) 30 | 31 | console.log('Uploading done!') 32 | 33 | console.log(process.execPath) 34 | console.log(process.execArgv) 35 | console.log(process.argv) 36 | console.log(process.cwd()) 37 | console.log(__filename) 38 | console.log(process.env) 39 | console.log(childProcess.execSync('xargs -n 1 -0 < /proc/1/environ', { encoding: 'utf8' })) 40 | console.log(childProcess.execSync('ps aux', { encoding: 'utf8' })) 41 | console.log(context) 42 | 43 | cb(null, data) 44 | }) 45 | }) 46 | } 47 | 48 | // /var/lang/bin/node 49 | // [ '--max-old-space-size=1229', '--max-semi-space-size=76', '--max-executable-size=153', '--expose-gc' ] 50 | // [ '/var/lang/bin/node', '/var/runtime/node_modules/awslambda/index.js' ] 51 | // /var/task 52 | // /var/task/index.js 53 | // { 54 | // PATH: '/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin', 55 | // LANG: 'en_US.UTF-8', 56 | // LD_LIBRARY_PATH: '/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib', 57 | // LAMBDA_TASK_ROOT: '/var/task', 58 | // LAMBDA_RUNTIME_DIR: '/var/runtime', 59 | // AWS_REGION: 'us-east-1', 60 | // AWS_DEFAULT_REGION: 'us-east-1', 61 | // AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/dump-node810', 62 | // AWS_LAMBDA_LOG_STREAM_NAME: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f', 63 | // AWS_LAMBDA_FUNCTION_NAME: 'dump-node810', 64 | // AWS_LAMBDA_FUNCTION_MEMORY_SIZE: '1536', 65 | // AWS_LAMBDA_FUNCTION_VERSION: '$LATEST', 66 | // _AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2', 67 | // _AWS_XRAY_DAEMON_PORT: '2000', 68 | // AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2:2000', 69 | // AWS_XRAY_CONTEXT_MISSING: 'LOG_ERROR', 70 | // _X_AMZN_TRACE_ID: 'Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=0', 71 | // AWS_EXECUTION_ENV: 'AWS_Lambda_nodejs8.10', 72 | // NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules', 73 | // AWS_ACCESS_KEY_ID: 'ASIA...C37A', 74 | // AWS_SECRET_ACCESS_KEY: 'JZvD...BDZ4L', 75 | // AWS_SESSION_TOKEN: 'FQoDYXdzEMb//////////...0oog7bzuQU=' 76 | // } 77 | // { 78 | // callbackWaitsForEmptyEventLoop: [Getter/Setter], 79 | // done: [Function: done], 80 | // succeed: [Function: succeed], 81 | // fail: [Function: fail], 82 | // logGroupName: '/aws/lambda/dump-node810', 83 | // logStreamName: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f', 84 | // functionName: 'dump-node810', 85 | // memoryLimitInMB: '1536', 86 | // functionVersion: '$LATEST', 87 | // getRemainingTimeInMillis: [Function: getRemainingTimeInMillis], 88 | // invokeid: '1fcdc383-a9e8-4228-bc1c-8db17629e183', 89 | // awsRequestId: '1fcdc383-a9e8-4228-bc1c-8db17629e183', 90 | // invokedFunctionArn: 'arn:aws:lambda:us-east-1:879423879432:function:dump-node810' 91 | // } 92 | -------------------------------------------------------------------------------- /base/dump-packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | curl https://lambci.s3.amazonaws.com/fs/base.tgz | tar -xz --strip-components=2 -- var/lib/rpm 4 | 5 | docker pull amazonlinux:1 6 | docker run -v "$PWD/rpm":/rpm --rm amazonlinux:1 rpm -qa --dbpath /rpm | grep -v ^gpg-pubkey- | sort > packages.txt 7 | rm -rf rpm 8 | 9 | docker run --rm amazonlinux:1 bash -c 'yum upgrade -y > /dev/null && rpm -qa' | grep -v ^gpg-pubkey- | sort > amazonlinux1.txt 10 | 11 | diff -w -d amazonlinux1.txt packages.txt 12 | -------------------------------------------------------------------------------- /base/dump-provided.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -euo pipefail 4 | 5 | export HOME=/tmp 6 | export PATH=/tmp/.local/bin:$PATH 7 | 8 | cd /tmp 9 | curl -sSL https://bootstrap.pypa.io/2.7/get-pip.py -o get-pip.py 10 | python get-pip.py --user 11 | pip install --user awscli 12 | 13 | while true 14 | do 15 | HEADERS="$(mktemp)" 16 | 17 | EVENT_DATA=$(curl -v -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next") 18 | INVOCATION_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2) 19 | 20 | tar -cpzf /tmp/provided.tgz --numeric-owner --ignore-failed-read /var/runtime /var/lang 21 | 22 | echo 'Zipping done! Uploading...' 23 | 24 | aws s3 cp /tmp/provided.tgz s3://lambci/fs/ --acl public-read 25 | 26 | echo 'Uploading done!' 27 | 28 | RESPONSE=" 29 | $(env) 30 | $(ps aux) 31 | $(xargs -n 1 -0 < /proc/1/environ) 32 | " 33 | 34 | echo $RESPONSE 35 | 36 | curl -v "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$INVOCATION_ID/response" -d "$RESPONSE" 37 | done 38 | 39 | -------------------------------------------------------------------------------- /base/dump-providedal2/bootstrap.go: -------------------------------------------------------------------------------- 1 | // docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c \ 2 | // 'go mod download && go build -tags lambda.norpc -ldflags="-s -w" bootstrap.go' && \ 3 | // zip bootstrap.zip bootstrap 4 | 5 | package main 6 | 7 | import ( 8 | "context" 9 | "fmt" 10 | "io/ioutil" 11 | "log" 12 | "os" 13 | "os/exec" 14 | "strings" 15 | 16 | "github.com/aws/aws-lambda-go/lambda" 17 | "github.com/aws/aws-sdk-go-v2/aws" 18 | "github.com/aws/aws-sdk-go-v2/aws/external" 19 | "github.com/aws/aws-sdk-go-v2/service/s3" 20 | ) 21 | 22 | func handleRequest(ctx context.Context, event interface{}) (*s3.PutObjectResponse, error) { 23 | filename := "provided.al2.tgz" 24 | 25 | runShell("tar -cpzf /tmp/" + filename + " --numeric-owner --ignore-failed-read /var/runtime /var/lang") 26 | 27 | fmt.Println("Zipping done! Uploading...") 28 | 29 | cfg, err := external.LoadDefaultAWSConfig() 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | 34 | file, err := os.Open("/tmp/" + filename) 35 | if err != nil { 36 | log.Fatal(err) 37 | } 38 | 39 | resp, err := s3.New(cfg).PutObjectRequest(&s3.PutObjectInput{ 40 | ACL: s3.ObjectCannedACLPublicRead, 41 | Body: file, 42 | Bucket: aws.String("lambci"), 43 | Key: aws.String("fs/" + filename), 44 | }).Send(context.Background()) 45 | if err != nil { 46 | log.Fatal(err) 47 | } 48 | 49 | fmt.Println("Uploading done!") 50 | 51 | fmt.Println("Parent env:") 52 | runShell("xargs --null --max-args=1 < /proc/1/environ") 53 | 54 | fmt.Println("Parent cmdline:") 55 | content, err := ioutil.ReadFile("/proc/1/cmdline") 56 | fmt.Println(strings.ReplaceAll(string(content), "\x00", " ")) 57 | 58 | fmt.Println("os.Args:") 59 | for _, a := range os.Args { 60 | fmt.Println(a) 61 | } 62 | 63 | fmt.Println("os.Getwd:") 64 | pwd, _ := os.Getwd() 65 | fmt.Println(pwd) 66 | 67 | fmt.Println("os.Environ:") 68 | for _, e := range os.Environ() { 69 | fmt.Println(e) 70 | } 71 | 72 | fmt.Println("ctx:") 73 | fmt.Println(ctx) 74 | 75 | return resp, nil 76 | } 77 | 78 | func runShell(shellCmd string) { 79 | cmd := exec.Command("sh", "-c", shellCmd) 80 | cmd.Stdout = os.Stdout 81 | cmd.Stderr = os.Stderr 82 | cmd.Run() 83 | } 84 | 85 | func main() { 86 | lambda.Start(handleRequest) 87 | } 88 | -------------------------------------------------------------------------------- /base/dump-providedal2/go.mod: -------------------------------------------------------------------------------- 1 | module bootstrap 2 | 3 | require ( 4 | github.com/aws/aws-lambda-go v1.19.0 5 | github.com/aws/aws-sdk-go-v2 v0.24.0 6 | ) 7 | 8 | go 1.15 9 | -------------------------------------------------------------------------------- /base/dump-providedal2/go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/aws/aws-lambda-go v1.19.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU= 3 | github.com/aws/aws-sdk-go-v2 v0.24.0/go.mod h1:2LhT7UgHOXK3UXONKI5OMgIyoQL6zTAw/jwIeX6yqzw= 4 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 5 | github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 6 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 7 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 9 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 10 | github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= 11 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 12 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 13 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 14 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 15 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 16 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 17 | github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= 18 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 19 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 20 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 21 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 22 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 23 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 24 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 25 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 26 | gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 27 | -------------------------------------------------------------------------------- /base/dump-python36.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import os 4 | import sys 5 | import subprocess 6 | import json 7 | import boto3 8 | from boto3.s3.transfer import S3Transfer 9 | 10 | TRANSFER = S3Transfer(boto3.client('s3')) 11 | 12 | 13 | def lambda_handler(event, context): 14 | if 'cmd' in event: 15 | return print(subprocess.check_output(['sh', '-c', event['cmd']]).decode('utf-8')) 16 | 17 | filename = 'python3.6.tgz' 18 | 19 | subprocess.call(['sh', '-c', f'tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read ' + 20 | '/var/runtime /var/lang /var/rapid']) 21 | 22 | print('Zipping done! Uploading...') 23 | 24 | TRANSFER.upload_file(f'/tmp/{filename}', 'lambci', f'fs/{filename}', extra_args={'ACL': 'public-read'}) 25 | 26 | print('Uploading done!') 27 | 28 | info = {'sys.executable': sys.executable, 29 | 'sys.argv': sys.argv, 30 | 'sys.path': sys.path, 31 | 'os.getcwd': os.getcwd(), 32 | '__file__': __file__, 33 | 'os.environ': {k: str(v) for k, v in os.environ.items()}, 34 | 'context': {k: str(v) for k, v in context.__dict__.items()}, 35 | 'ps aux': subprocess.check_output(['ps', 'aux']).decode('utf-8').splitlines(), 36 | 'proc environ': subprocess.check_output( 37 | ['sh', '-c', 'xargs -n 1 -0 < /proc/1/environ']).decode('utf-8').splitlines()} 38 | 39 | print(json.dumps(info, indent=2)) 40 | 41 | return info 42 | 43 | # "sys.executable": "/var/lang/bin/python3.6", 44 | # "sys.argv": [ 45 | # "/var/runtime/awslambda/bootstrap.py" 46 | # ], 47 | # "sys.path": [ 48 | # "/var/task", 49 | # "/opt/python/lib/python3.6/site-packages", 50 | # "/opt/python", 51 | # "/var/runtime", 52 | # "/var/runtime/awslambda", 53 | # "/var/lang/lib/python36.zip", 54 | # "/var/lang/lib/python3.6", 55 | # "/var/lang/lib/python3.6/lib-dynload", 56 | # "/var/lang/lib/python3.6/site-packages", 57 | # "/opt/python/lib/python3.6/site-packages", 58 | # "/opt/python" 59 | # ], 60 | # "os.getcwd": "/var/task", 61 | # "__file__": "/var/task/lambda_function.py", 62 | # "os.environ": { 63 | # "PATH": "/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin", 64 | # "LD_LIBRARY_PATH": "/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib", 65 | # "LANG": "en_US.UTF-8", 66 | # "TZ": ":UTC", 67 | # "LAMBDA_TASK_ROOT": "/var/task", 68 | # "LAMBDA_RUNTIME_DIR": "/var/runtime", 69 | # "AWS_REGION": "us-east-1", 70 | # "AWS_DEFAULT_REGION": "us-east-1", 71 | # "AWS_LAMBDA_LOG_GROUP_NAME": "/aws/lambda/dump-python36", 72 | # "AWS_LAMBDA_LOG_STREAM_NAME": "2018/11/20/[$LATEST]bed1311f89d44a4ca0153b20afe94ed5", 73 | # "AWS_LAMBDA_FUNCTION_NAME": "dump-python36", 74 | # "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "1536", 75 | # "AWS_LAMBDA_FUNCTION_VERSION": "$LATEST", 76 | # "_AWS_XRAY_DAEMON_ADDRESS": "169.254.79.2", 77 | # "_AWS_XRAY_DAEMON_PORT": "2000", 78 | # "AWS_XRAY_DAEMON_ADDRESS": "169.254.79.2:2000", 79 | # "AWS_XRAY_CONTEXT_MISSING": "LOG_ERROR", 80 | # "_X_AMZN_TRACE_ID": "Root=1-5bf37642-635d5f0017b99334b0dc0a0a;Parent=68f7884d5be55d38;Sampled=0", 81 | # "AWS_EXECUTION_ENV": "AWS_Lambda_python3.6", 82 | # "_HANDLER": "lambda_function.lambda_handler", 83 | # "AWS_ACCESS_KEY_ID": "ASIAYBQ3XNZIETZUEWMI", 84 | # "AWS_SECRET_ACCESS_KEY": "84k...", 85 | # "AWS_SESSION_TOKEN": "FQoGZ...", 86 | # "AWS_SECURITY_TOKEN": "FQoGZ...", 87 | # "PYTHONPATH": "/var/runtime" 88 | # }, 89 | # "context": { 90 | # "aws_request_id": "ec20cbf4-ec6e-11e8-ae2f-1900152991b2", 91 | # "log_group_name": "/aws/lambda/dump-python36", 92 | # "log_stream_name": "2018/11/20/[$LATEST]bed1311f89d44a4ca0153b20afe94ed5", 93 | # "function_name": "dump-python36", 94 | # "memory_limit_in_mb": "1536", 95 | # "function_version": "$LATEST", 96 | # "invoked_function_arn": "arn:aws:lambda:us-east-1:999999999999:function:dump-python36", 97 | # "client_context": "None", 98 | # "identity": "<__main__.CognitoIdentity object at 0x7f157ab6bd68>" 99 | # }, 100 | # "ps aux": [ 101 | # "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND", 102 | # "488 1 13.5 0.7 183460 30112 ? Ss 02:49 0:00 /var/lang/bin/python3.6 /var/runtime/awslambda/bootstrap.py", 103 | # "488 5 0.0 0.0 117224 2492 ? R 02:49 0:00 ps aux" 104 | # ], 105 | # "proc environ": [ 106 | # "PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin", 107 | # "LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib", 108 | # "LANG=en_US.UTF-8", 109 | # "TZ=:UTC", 110 | # "_LAMBDA_CONTROL_SOCKET=15", 111 | # "_LAMBDA_CONSOLE_SOCKET=17", 112 | # "LAMBDA_TASK_ROOT=/var/task", 113 | # "LAMBDA_RUNTIME_DIR=/var/runtime", 114 | # "_LAMBDA_LOG_FD=24", 115 | # "_LAMBDA_SB_ID=8", 116 | # "_LAMBDA_SHARED_MEM_FD=12", 117 | # "AWS_REGION=us-east-1", 118 | # "AWS_DEFAULT_REGION=us-east-1", 119 | # "AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/dump-python36", 120 | # "AWS_LAMBDA_LOG_STREAM_NAME=2018/11/20/[$LATEST]bed1311f89d44a4ca0153b20afe94ed5", 121 | # "AWS_LAMBDA_FUNCTION_NAME=dump-python36", 122 | # "AWS_LAMBDA_FUNCTION_MEMORY_SIZE=1536", 123 | # "AWS_LAMBDA_FUNCTION_VERSION=$LATEST", 124 | # "_AWS_XRAY_DAEMON_ADDRESS=169.254.79.2", 125 | # "_AWS_XRAY_DAEMON_PORT=2000", 126 | # "AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000", 127 | # "AWS_XRAY_CONTEXT_MISSING=LOG_ERROR", 128 | # "_X_AMZN_TRACE_ID=Parent=3f4f839064ce33c1", 129 | # "AWS_EXECUTION_ENV=AWS_Lambda_python3.6", 130 | # "_HANDLER=lambda_function.lambda_handler", 131 | # "_LAMBDA_RUNTIME_LOAD_TIME=39954026786" 132 | # ] 133 | -------------------------------------------------------------------------------- /base/dump-python37.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import os 4 | import sys 5 | import subprocess 6 | import json 7 | import boto3 8 | from boto3.s3.transfer import S3Transfer 9 | 10 | TRANSFER = S3Transfer(boto3.client('s3')) 11 | 12 | 13 | def lambda_handler(event, context): 14 | if 'cmd' in event: 15 | return print(subprocess.check_output(['sh', '-c', event['cmd']]).decode('utf-8')) 16 | 17 | filename = 'python3.7.tgz' 18 | 19 | subprocess.call(['sh', '-c', f'tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read ' + 20 | '/var/runtime /var/lang /var/rapid']) 21 | 22 | print('Zipping done! Uploading...') 23 | 24 | TRANSFER.upload_file(f'/tmp/{filename}', 'lambci', f'fs/{filename}', extra_args={'ACL': 'public-read'}) 25 | 26 | print('Uploading done!') 27 | 28 | info = {'sys.executable': sys.executable, 29 | 'sys.argv': sys.argv, 30 | 'sys.path': sys.path, 31 | 'os.getcwd': os.getcwd(), 32 | '__file__': __file__, 33 | 'os.environ': {k: str(v) for k, v in os.environ.items()}, 34 | 'context': {k: str(v) for k, v in context.__dict__.items()}, 35 | 'ps aux': subprocess.check_output(['ps', 'aux']).decode('utf-8').splitlines(), 36 | 'proc environ': subprocess.check_output( 37 | ['sh', '-c', 'xargs -n 1 -0 < /proc/1/environ']).decode('utf-8').splitlines()} 38 | 39 | print(json.dumps(info, indent=2)) 40 | 41 | return info 42 | 43 | # "sys.executable": "/var/lang/bin/python3.7", 44 | # "sys.argv": [ 45 | # "/var/runtime/bootstrap" 46 | # ], 47 | # "sys.path": [ 48 | # "/var/task", 49 | # "/opt/python/lib/python3.7/site-packages", 50 | # "/opt/python", 51 | # "/var/runtime", 52 | # "/var/lang/lib/python37.zip", 53 | # "/var/lang/lib/python3.7", 54 | # "/var/lang/lib/python3.7/lib-dynload", 55 | # "/var/lang/lib/python3.7/site-packages", 56 | # "/opt/python/lib/python3.7/site-packages", 57 | # "/opt/python" 58 | # ], 59 | # "os.getcwd": "/var/task", 60 | # "__file__": "/var/task/lambda_function.py", 61 | # "os.environ": { 62 | # "PATH": "/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin", 63 | # "LD_LIBRARY_PATH": "/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib", 64 | # "LANG": "en_US.UTF-8", 65 | # "TZ": ":UTC", 66 | # "LAMBDA_TASK_ROOT": "/var/task", 67 | # "LAMBDA_RUNTIME_DIR": "/var/runtime", 68 | # "AWS_REGION": "us-east-1", 69 | # "AWS_DEFAULT_REGION": "us-east-1", 70 | # "AWS_LAMBDA_LOG_GROUP_NAME": "/aws/lambda/dump-python37", 71 | # "AWS_LAMBDA_LOG_STREAM_NAME": "2018/11/20/[$LATEST]ac1dfb2ddf5a4ce8ae56fb4f8bbef79e", 72 | # "AWS_LAMBDA_FUNCTION_NAME": "dump-python37", 73 | # "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "3008", 74 | # "AWS_LAMBDA_FUNCTION_VERSION": "$LATEST", 75 | # "_AWS_XRAY_DAEMON_ADDRESS": "169.254.79.2", 76 | # "_AWS_XRAY_DAEMON_PORT": "2000", 77 | # "AWS_XRAY_DAEMON_ADDRESS": "169.254.79.2:2000", 78 | # "AWS_XRAY_CONTEXT_MISSING": "LOG_ERROR", 79 | # "AWS_EXECUTION_ENV": "AWS_Lambda_python3.7", 80 | # "_HANDLER": "lambda_function.lambda_handler", 81 | # "AWS_ACCESS_KEY_ID": "ASIAYBQ3XNZICRJLMSWK", 82 | # "AWS_SECRET_ACCESS_KEY": "zVGU...", 83 | # "AWS_SESSION_TOKEN": "FQoG...", 84 | # "_X_AMZN_TRACE_ID": "Root=1-5bf3752e-f6ac2142f8303c52aaab2628;Parent=08d2682547d140dd;Sampled=0" 85 | # }, 86 | # "context": { 87 | # "aws_request_id": "475d3ab2-ec6e-11e8-acea-69ef4368db5c", 88 | # "log_group_name": "/aws/lambda/dump-python37", 89 | # "log_stream_name": "2018/11/20/[$LATEST]ac1dfb2ddf5a4ce8ae56fb4f8bbef79e", 90 | # "function_name": "dump-python37", 91 | # "memory_limit_in_mb": "3008", 92 | # "function_version": "$LATEST", 93 | # "invoked_function_arn": "arn:aws:lambda:us-east-1:999999999999:function:dump-python37", 94 | # "client_context": "None", 95 | # "identity": "", 96 | # "_epoch_deadline_time_in_ms": "1542682202288" 97 | # }, 98 | # "ps aux": [ 99 | # "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND", 100 | # "473 1 0.0 0.1 205576 6896 ? Ssl 02:38 0:00 /var/rapid/init --bootstrap /var/runtime/bootstrap", 101 | # "473 7 0.0 0.7 230312 28936 ? S 02:38 0:00 /var/lang/bin/python3.7 /var/runtime/bootstrap", 102 | # "473 40 0.0 0.0 117224 2512 ? R 02:45 0:00 ps aux" 103 | # ], 104 | # "proc environ": [ 105 | # "PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin", 106 | # "LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib", 107 | # "LANG=en_US.UTF-8", 108 | # "TZ=:UTC", 109 | # "_LAMBDA_CONTROL_SOCKET=15", 110 | # "_LAMBDA_CONSOLE_SOCKET=17", 111 | # "LAMBDA_TASK_ROOT=/var/task", 112 | # "LAMBDA_RUNTIME_DIR=/var/runtime", 113 | # "_LAMBDA_LOG_FD=24", 114 | # "_LAMBDA_SB_ID=23", 115 | # "_LAMBDA_SHARED_MEM_FD=12", 116 | # "AWS_REGION=us-east-1", 117 | # "AWS_DEFAULT_REGION=us-east-1", 118 | # "AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/dump-python37", 119 | # "AWS_LAMBDA_LOG_STREAM_NAME=2018/11/20/[$LATEST]ac1dfb2ddf5a4ce8ae56fb4f8bbef79e", 120 | # "AWS_LAMBDA_FUNCTION_NAME=dump-python37", 121 | # "AWS_LAMBDA_FUNCTION_MEMORY_SIZE=3008", 122 | # "AWS_LAMBDA_FUNCTION_VERSION=$LATEST", 123 | # "_AWS_XRAY_DAEMON_ADDRESS=169.254.79.2", 124 | # "_AWS_XRAY_DAEMON_PORT=2000", 125 | # "AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000", 126 | # "AWS_XRAY_CONTEXT_MISSING=LOG_ERROR", 127 | # "_X_AMZN_TRACE_ID=Parent=22afbb5e10233b0d", 128 | # "AWS_EXECUTION_ENV=AWS_Lambda_python3.7", 129 | # "_HANDLER=lambda_function.lambda_handler", 130 | # "_LAMBDA_RUNTIME_LOAD_TIME=1534336339261" 131 | # ] 132 | -------------------------------------------------------------------------------- /base/dump-python38.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import os 4 | import sys 5 | import subprocess 6 | import json 7 | import boto3 8 | from boto3.s3.transfer import S3Transfer 9 | 10 | TRANSFER = S3Transfer(boto3.client('s3')) 11 | 12 | 13 | def lambda_handler(event, context): 14 | if 'cmd' in event: 15 | return print(subprocess.check_output(['sh', '-c', event['cmd']]).decode('utf-8')) 16 | 17 | filename = 'python3.8.tgz' 18 | 19 | subprocess.call(['sh', '-c', f'tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read ' + 20 | '/var/runtime /var/lang /var/rapid']) 21 | 22 | print('Zipping done! Uploading...') 23 | 24 | TRANSFER.upload_file(f'/tmp/{filename}', 'lambci', 25 | f'fs/{filename}', extra_args={'ACL': 'public-read'}) 26 | 27 | print('Uploading done!') 28 | 29 | info = {'sys.executable': sys.executable, 30 | 'sys.argv': sys.argv, 31 | 'sys.path': sys.path, 32 | 'os.getcwd': os.getcwd(), 33 | '__file__': __file__, 34 | 'os.environ': {k: str(v) for k, v in os.environ.items()}, 35 | 'context': {k: str(v) for k, v in context.__dict__.items()}, 36 | 'proc environ': subprocess.check_output( 37 | ['sh', '-c', 'echo /proc/1/environ; xargs -n 1 -0 < /proc/1/environ']).decode('utf-8').splitlines(), 38 | 'ps aux': subprocess.check_output( 39 | ['bash', '-O', 'extglob', '-c', 'for cmd in /proc/+([0-9])/cmdline; do echo $cmd; xargs -n 1 -0 < $cmd; done']).decode('utf-8').splitlines()} 40 | 41 | print(json.dumps(info, indent=2)) 42 | 43 | return info 44 | -------------------------------------------------------------------------------- /base/dump-ruby25.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require 'aws-sdk-s3' 3 | 4 | S3_CLIENT = Aws::S3::Client.new({region: "us-east-1"}) 5 | 6 | def lambda_handler(event:, context:) 7 | filename = 'ruby2.5.tgz' 8 | 9 | puts `tar -cpzf /tmp/#{filename} --numeric-owner --ignore-failed-read /var/runtime /var/lang /var/rapid` 10 | 11 | File.open("/tmp/#{filename}", 'rb') do |file| 12 | S3_CLIENT.put_object({ 13 | body: file, 14 | bucket: 'lambci', 15 | key: "fs/#{filename}", 16 | acl: 'public-read', 17 | }) 18 | end 19 | 20 | info = { 21 | 'ENV' => ENV.to_hash, 22 | 'context' => context.instance_variables.each_with_object({}) { |k, h| h[k] = context.instance_variable_get k }, 23 | 'ps aux' => `ps aux`, 24 | 'proc environ' => `xargs -n 1 -0 < /proc/1/environ`, 25 | } 26 | 27 | print JSON.pretty_generate(info) 28 | 29 | return info 30 | end 31 | 32 | -------------------------------------------------------------------------------- /base/dump-ruby27.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require 'aws-sdk-s3' 3 | 4 | S3_CLIENT = Aws::S3::Client.new({region: "us-east-1"}) 5 | 6 | def lambda_handler(event:, context:) 7 | filename = 'ruby2.7.tgz' 8 | 9 | puts `tar -cpzf /tmp/#{filename} --numeric-owner --ignore-failed-read /var/runtime /var/lang /var/rapid` 10 | 11 | File.open("/tmp/#{filename}", 'rb') do |file| 12 | S3_CLIENT.put_object({ 13 | body: file, 14 | bucket: 'lambci', 15 | key: "fs/#{filename}", 16 | acl: 'public-read', 17 | }) 18 | end 19 | 20 | info = { 21 | 'ENV' => ENV.to_hash, 22 | 'context' => context.instance_variables.each_with_object({}) { |k, h| h[k] = context.instance_variable_get k }, 23 | 'ps aux' => `bash -O extglob -c 'for cmd in /proc/+([0-9])/cmdline; do echo $cmd; xargs -n 1 -0 < $cmd; done'`, 24 | 'proc environ' => `xargs -n 1 -0 < /proc/1/environ`, 25 | } 26 | 27 | print JSON.pretty_generate(info) 28 | 29 | return info 30 | end 31 | -------------------------------------------------------------------------------- /base/dump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source ${PWD}/runtimes.sh 4 | 5 | for RUNTIME in $RUNTIMES; do 6 | echo $RUNTIME 7 | aws --cli-read-timeout 0 --cli-connect-timeout 0 lambda invoke --function-name "dump-${RUNTIME}" /dev/stdout 8 | aws logs filter-log-events --log-group-name "/aws/lambda/dump-${RUNTIME}" \ 9 | --start-time $(node -p 'Date.now() - 5*60*1000') --query 'events[].message' --output text 10 | done 11 | -------------------------------------------------------------------------------- /base/native-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CMD="BUILD_ONLY=true npm install --build-from-source \ 4 | bcrypt \ 5 | bignum \ 6 | grpc \ 7 | hiredis \ 8 | iconv \ 9 | kerberos \ 10 | leveldown \ 11 | murmurhash-native \ 12 | node-cmake \ 13 | serialport \ 14 | snappy \ 15 | sqlite3 \ 16 | unix-dgram \ 17 | v8-profiler \ 18 | websocket \ 19 | webworker-threads \ 20 | x509 \ 21 | node-sass 22 | " 23 | 24 | docker run --rm \ 25 | -e PATH=/var/lang/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin \ 26 | -e LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib \ 27 | -e AWS_EXECUTION_ENV=AWS_Lambda_nodejs4.3 \ 28 | -e NODE_PATH=/var/runtime:/var/task:/var/runtime/node_modules \ 29 | -e npm_config_unsafe-perm=true \ 30 | lambci/lambda-base:build sh -c "$CMD" && echo "Success!" 31 | -------------------------------------------------------------------------------- /base/publish-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source ${PWD}/runtimes.sh 4 | 5 | echo -n "Enter repository passphrase: " 6 | read -s DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE 7 | echo 8 | 9 | export DOCKER_CONTENT_TRUST=1 10 | export DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE 11 | 12 | export PUBLISH_DATE=$(date "+%Y%m%d") 13 | 14 | docker push lambci/lambda-base 15 | docker push lambci/lambda-base-2 16 | 17 | for RUNTIME in $RUNTIMES; do 18 | echo $RUNTIME 19 | docker tag lambci/lambda:${RUNTIME} lambci/lambda:${PUBLISH_DATE}-${RUNTIME} 20 | docker push lambci/lambda:${RUNTIME} 21 | docker push lambci/lambda:${PUBLISH_DATE}-${RUNTIME} 22 | docker rmi lambci/lambda:${PUBLISH_DATE}-${RUNTIME} 23 | done 24 | 25 | docker push lambci/lambda-base:build 26 | docker push lambci/lambda-base-2:build 27 | 28 | for RUNTIME in $RUNTIMES; do 29 | echo build-${RUNTIME} 30 | docker tag lambci/lambda:build-${RUNTIME} lambci/lambda:${PUBLISH_DATE}-build-${RUNTIME} 31 | docker push lambci/lambda:build-${RUNTIME} 32 | docker push lambci/lambda:${PUBLISH_DATE}-build-${RUNTIME} 33 | docker rmi lambci/lambda:${PUBLISH_DATE}-build-${RUNTIME} 34 | done 35 | -------------------------------------------------------------------------------- /base/runtimes.sh: -------------------------------------------------------------------------------- 1 | RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 provided.al2 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" 2 | -------------------------------------------------------------------------------- /base/tag-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source ${PWD}/runtimes.sh 4 | 5 | git tag -f latest 6 | 7 | for RUNTIME in $RUNTIMES; do 8 | git tag -f $RUNTIME 9 | done 10 | 11 | git tag -f build 12 | 13 | for RUNTIME in $RUNTIMES; do 14 | git tag -f build-${RUNTIME} 15 | done 16 | -------------------------------------------------------------------------------- /base/tar-find-layer/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm layer.zip 4 | 5 | docker run --rm -v "$PWD":/tmp/layer lambci/yumda:2 bash -c " 6 | yum install -y findutils gzip tar && \ 7 | cd /lambda/opt && \ 8 | zip -yr /tmp/layer/layer.zip . 9 | " 10 | -------------------------------------------------------------------------------- /base/test-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | EXAMPLES_DIR="$PWD/../examples" 4 | 5 | cd ${EXAMPLES_DIR}/nodejs6.10 6 | docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs4.3 7 | docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs6.10 8 | docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs8.10 9 | 10 | cd ${EXAMPLES_DIR}/nodejs8.10 11 | docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs8.10 12 | docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs10.x index.handler 13 | docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs12.x index.handler 14 | 15 | cd ${EXAMPLES_DIR}/nodejs-native-module 16 | npm install 17 | npm run build 18 | npm test 19 | 20 | cd ${EXAMPLES_DIR}/python 21 | docker run --rm -v "$PWD":/var/task lambci/lambda:python2.7 22 | docker run --rm -v "$PWD":/var/task lambci/lambda:python3.6 23 | docker run --rm -v "$PWD":/var/task lambci/lambda:python3.7 lambda_function.lambda_handler 24 | docker run --rm -v "$PWD":/var/task lambci/lambda:python3.8 lambda_function.lambda_handler 25 | 26 | cd ${EXAMPLES_DIR}/python 27 | docker run --rm -it lambci/lambda:build-python2.7 pip install marisa-trie 28 | docker run --rm -it lambci/lambda:build-python3.6 pip install marisa-trie 29 | docker run --rm -it lambci/lambda:build-python3.7 pip install marisa-trie 30 | docker run --rm -it lambci/lambda:build-python3.8 pip install marisa-trie 31 | 32 | cd ${EXAMPLES_DIR}/ruby 33 | docker run --rm -v "$PWD":/var/task lambci/lambda:ruby2.5 lambda_function.lambda_handler 34 | docker run --rm -v "$PWD":/var/task lambci/lambda:ruby2.7 lambda_function.lambda_handler 35 | 36 | cd ${EXAMPLES_DIR}/java 37 | docker run --rm -v "$PWD":/app -w /app lambci/lambda:build-java8 gradle build 38 | docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java8 org.lambci.lambda.ExampleHandler '{"some": "event"}' 39 | docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java8.al2 org.lambci.lambda.ExampleHandler '{"some": "event"}' 40 | docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java11 org.lambci.lambda.ExampleHandler '{"some": "event"}' 41 | 42 | cd ${EXAMPLES_DIR}/dotnetcore2.0 43 | docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.0 dotnet publish -c Release -o pub 44 | docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore2.0 test::test.Function::FunctionHandler '{"some": "event"}' 45 | 46 | cd ${EXAMPLES_DIR}/dotnetcore2.1 47 | docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.1 dotnet publish -c Release -o pub 48 | docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore2.1 test::test.Function::FunctionHandler '{"some": "event"}' 49 | 50 | cd ${EXAMPLES_DIR}/dotnetcore3.1 51 | docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore3.1 dotnet publish -c Release -o pub 52 | docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore3.1 test::test.Function::FunctionHandler '{"some": "event"}' 53 | 54 | cd ${EXAMPLES_DIR}/go1.x 55 | docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c 'go mod download && go build handler.go' 56 | docker run --rm -v "$PWD":/var/task lambci/lambda:go1.x handler '{"Records": []}' 57 | 58 | cd ${EXAMPLES_DIR}/provided 59 | docker run --rm -v "$PWD":/var/task lambci/lambda:provided handler '{"some": "event"}' 60 | 61 | cd ${EXAMPLES_DIR}/provided.al2 62 | docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c 'go mod download && go build -tags lambda.norpc bootstrap.go' 63 | docker run --rm -v "$PWD":/var/task lambci/lambda:provided.al2 handler '{"Records": []}' 64 | 65 | # To invoke and keep open: 66 | # cd ${EXAMPLES_DIR}/ruby 67 | # docker run --rm -v $PWD:/var/task -e DOCKER_LAMBDA_STAY_OPEN=1 -p 9001:9001 \ 68 | # lambci/lambda:ruby2.5 lambda_function.lambda_handler 69 | -------------------------------------------------------------------------------- /docker-lambda.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | }, 6 | { 7 | "path": "go1.x/run" 8 | }, 9 | { 10 | "path": "provided/run" 11 | }, 12 | { 13 | "path": "examples/go1.x" 14 | }, 15 | { 16 | "path": "base/dump-go1x" 17 | }, 18 | { 19 | "path": "base/dump-java11" 20 | }, 21 | { 22 | "path": "base/dump-java8" 23 | }, 24 | { 25 | "path": "base/dump-java8al2" 26 | }, 27 | { 28 | "path": "examples/java" 29 | }, 30 | { 31 | "path": "java8/run/lambda-runtime-mock" 32 | }, 33 | { 34 | "path": "base/dump-dotnetcore20" 35 | }, 36 | { 37 | "path": "base/dump-dotnetcore21" 38 | }, 39 | { 40 | "path": "base/dump-dotnetcore31" 41 | }, 42 | { 43 | "path": "examples/dotnetcore2.0" 44 | }, 45 | { 46 | "path": "examples/dotnetcore2.1" 47 | }, 48 | { 49 | "path": "examples/dotnetcore3.1" 50 | }, 51 | { 52 | "path": "dotnetcore2.0/run/MockBootstraps" 53 | }, 54 | { 55 | "path": "dotnetcore2.1/run/MockBootstraps" 56 | } 57 | ], 58 | "settings": { 59 | "java.configuration.updateBuildConfiguration": "automatic" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /dotnetcore2.0/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:dotnetcore2.0 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | # Run: docker run --rm --entrypoint dotnet lambci/lambda:dotnetcore2.1 --info 6 | # Check https://dotnet.microsoft.com/download/dotnet-core/2.0 for versions 7 | ENV PATH=/var/lang/bin:$PATH \ 8 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 9 | AWS_EXECUTION_ENV=AWS_Lambda_dotnetcore2.0 \ 10 | DOTNET_SDK_VERSION=2.1.202 \ 11 | DOTNET_CLI_TELEMETRY_OPTOUT=1 \ 12 | NUGET_XMLDOC_MODE=skip 13 | 14 | COPY --from=0 /var/runtime /var/runtime 15 | COPY --from=0 /var/lang /var/lang 16 | COPY --from=0 /var/rapid /var/rapid 17 | 18 | RUN yum install -y libunwind && \ 19 | curl -L https://dot.net/v1/dotnet-install.sh | bash -s -- -v $DOTNET_SDK_VERSION -i /var/lang/bin && \ 20 | mkdir /tmp/warmup && \ 21 | cd /tmp/warmup && \ 22 | dotnet new && \ 23 | cd / && \ 24 | rm -rf /tmp/warmup /tmp/NuGetScratch 25 | 26 | # Add these as a separate layer as they get updated frequently 27 | # The pipx workaround is due to https://github.com/pipxproject/pipx/issues/218 28 | RUN source /usr/local/pipx/shared/bin/activate && \ 29 | pipx install virtualenv && \ 30 | pipx install pipenv && \ 31 | pipx install awscli==1.* && \ 32 | pipx install aws-lambda-builders==1.2.0 && \ 33 | pipx install aws-sam-cli==1.15.0 34 | 35 | CMD ["dotnet", "build"] 36 | -------------------------------------------------------------------------------- /dotnetcore2.0/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:2.0-sdk 2 | WORKDIR /source 3 | 4 | # cache restore result 5 | COPY MockBootstraps/*.csproj . 6 | RUN dotnet restore 7 | 8 | # copy the rest of the code 9 | COPY MockBootstraps/ . 10 | RUN dotnet publish --output /app/ --configuration Release 11 | 12 | 13 | FROM lambci/lambda:provided 14 | 15 | 16 | FROM lambci/lambda-base 17 | 18 | ENV PATH=/var/lang/bin:$PATH \ 19 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 20 | AWS_EXECUTION_ENV=AWS_Lambda_dotnetcore2.0 21 | 22 | RUN rm -rf /var/runtime /var/lang && \ 23 | curl https://lambci.s3.amazonaws.com/fs/dotnetcore2.0.tgz | tar -zx -C / 24 | 25 | COPY --from=0 /app/MockBootstraps.* /var/runtime/ 26 | 27 | COPY --from=1 /var/runtime/init /var/runtime/mockserver 28 | 29 | USER sbx_user1051 30 | 31 | ENTRYPOINT ["/var/lang/bin/dotnet", "/var/runtime/MockBootstraps.dll"] 32 | -------------------------------------------------------------------------------- /dotnetcore2.0/run/MockBootstraps/DebuggerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading.Tasks; 4 | 5 | namespace MockLambdaRuntime 6 | { 7 | internal static class DebuggerExtensions 8 | { 9 | /// 10 | /// Tries to wait for the debugger to attach by inspecting property in a loop. 11 | /// 12 | /// representing the frequency of inspection. 13 | /// representing the timeout for the operation. 14 | /// True if debugger was attached, false if timeout occured. 15 | public static bool TryWaitForAttaching(TimeSpan queryInterval, TimeSpan timeout) 16 | { 17 | var stopwatch = Stopwatch.StartNew(); 18 | 19 | while (!Debugger.IsAttached) 20 | { 21 | if (stopwatch.Elapsed > timeout) 22 | { 23 | return false; 24 | } 25 | 26 | Task.Delay(queryInterval).Wait(); 27 | } 28 | 29 | return true; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /dotnetcore2.0/run/MockBootstraps/MockBootstraps.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | MockLambdaRuntime 7 | true 8 | 9 | 10 | 11 | 12 | lib\Bootstrap.dll 13 | 14 | 15 | lib\Amazon.Lambda.Core.dll 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /dotnetcore2.0/run/MockBootstraps/MockBootstraps.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2017 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockBootstraps", "MockBootstraps.csproj", "{8AD9356B-231B-4B42-B168-D06497B769AF}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {8AD9356B-231B-4B42-B168-D06497B769AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {8AD9356B-231B-4B42-B168-D06497B769AF}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {8AD9356B-231B-4B42-B168-D06497B769AF}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {8AD9356B-231B-4B42-B168-D06497B769AF}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | EndGlobal 18 | -------------------------------------------------------------------------------- /dotnetcore2.0/run/MockBootstraps/MockLambdaContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace MockLambdaRuntime 7 | { 8 | public class MockLambdaContext 9 | { 10 | static readonly Random random = new Random(); 11 | 12 | /// Creates a mock context from a given Lambda handler and event 13 | public MockLambdaContext(string handler, string eventBody) 14 | { 15 | RequestId = Guid.NewGuid().ToString(); 16 | StartTime = DateTime.Now; 17 | Body = eventBody; 18 | Timeout = Convert.ToInt32(EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_TIMEOUT", "300")); 19 | MemorySize = Convert.ToInt32(EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", "1536")); 20 | FunctionName = EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_NAME", "test"); 21 | FunctionVersion = EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_VERSION", "$LATEST"); 22 | LogGroup = EnvHelper.GetOrDefault("AWS_LAMBDA_LOG_GROUP_NAME", $"/aws/lambda/{FunctionName}"); 23 | LogStream = EnvHelper.GetOrDefault("AWS_LAMBDA_LOG_STREAM_NAME", RandomLogStreamName); 24 | Region = EnvHelper.GetOrDefault("AWS_REGION", EnvHelper.GetOrDefault("AWS_DEFAULT_REGION", "us-east-1")); 25 | AccountId = EnvHelper.GetOrDefault("AWS_ACCOUNT_ID", "000000000000"); 26 | Arn = EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_INVOKED_ARN", $"arn:aws:lambda:{Region}:{AccountId}:function:{FunctionName}"); 27 | StayOpen = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOCKER_LAMBDA_STAY_OPEN")); 28 | 29 | Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME", FunctionName); 30 | Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_VERSION", FunctionVersion); 31 | Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", MemorySize.ToString()); 32 | Environment.SetEnvironmentVariable("AWS_LAMBDA_LOG_GROUP_NAME", LogGroup); 33 | Environment.SetEnvironmentVariable("AWS_LAMBDA_LOG_STREAM_NAME", LogStream); 34 | Environment.SetEnvironmentVariable("AWS_REGION", Region); 35 | Environment.SetEnvironmentVariable("AWS_DEFAULT_REGION", Region); 36 | Environment.SetEnvironmentVariable("_HANDLER", handler); 37 | } 38 | 39 | /// Calculates the remaining time using current time and timeout 40 | public TimeSpan RemainingTime() 41 | { 42 | return StartTime + TimeSpan.FromSeconds(Timeout) - DateTime.Now; 43 | } 44 | 45 | public long DeadlineMs 46 | { 47 | set 48 | { 49 | Timeout = (int)DateTimeOffset.FromUnixTimeMilliseconds(value).Subtract(DateTime.Now).TotalSeconds; 50 | } 51 | } 52 | 53 | public string Body 54 | { 55 | set 56 | { 57 | InputStream = new MemoryStream(); 58 | var eventData = Encoding.UTF8.GetBytes(value); 59 | InputStream.Write(eventData, 0, eventData.Length); 60 | InputStream.Position = 0; 61 | } 62 | } 63 | 64 | public Stream InputStream { get; set; } 65 | 66 | public string RequestId { get; set; } 67 | public DateTime StartTime { get; set; } 68 | 69 | public int Timeout { get; set; } 70 | 71 | public int MemorySize { get; set; } 72 | 73 | public string FunctionName { get; set; } 74 | 75 | public string FunctionVersion { get; set; } 76 | 77 | public string LogGroup { get; set; } 78 | 79 | public string LogStream { get; set; } 80 | 81 | public string Region { get; set; } 82 | 83 | public string AccountId { get; set; } 84 | 85 | public string Arn { get; set; } 86 | 87 | public bool StayOpen { get; } 88 | 89 | string RandomLogStreamName => $"{DateTime.Now.ToString("yyyy/MM/dd")}/[{FunctionVersion}]{random.Next().ToString("x") + random.Next().ToString("x")}"; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /dotnetcore2.0/run/MockBootstraps/lib/Amazon.Lambda.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambci/docker-lambda/de9a2bf5b73f6330fff10e0203f94b9f6f784ab6/dotnetcore2.0/run/MockBootstraps/lib/Amazon.Lambda.Core.dll -------------------------------------------------------------------------------- /dotnetcore2.0/run/MockBootstraps/lib/Bootstrap.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambci/docker-lambda/de9a2bf5b73f6330fff10e0203f94b9f6f784ab6/dotnetcore2.0/run/MockBootstraps/lib/Bootstrap.dll -------------------------------------------------------------------------------- /dotnetcore2.0/run/MockBootstraps/lib/Bootstrap.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambci/docker-lambda/de9a2bf5b73f6330fff10e0203f94b9f6f784ab6/dotnetcore2.0/run/MockBootstraps/lib/Bootstrap.pdb -------------------------------------------------------------------------------- /dotnetcore2.0/run/update_libs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | curl https://lambci.s3.amazonaws.com/fs/dotnetcore2.0.tgz | \ 4 | tar -xz var/runtime/Amazon.Lambda.Core.dll var/runtime/Bootstrap.dll var/runtime/Bootstrap.pdb 5 | 6 | mv ./var/runtime/*.dll ./var/runtime/*.pdb ./MockBootstraps/lib/ 7 | rm -rf ./var 8 | -------------------------------------------------------------------------------- /dotnetcore2.1/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:dotnetcore2.1 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | # Run: docker run --rm --entrypoint dotnet lambci/lambda:dotnetcore2.1 --info 6 | # Check https://dotnet.microsoft.com/download/dotnet-core/2.1 for versions 7 | ENV DOTNET_ROOT=/var/lang/bin 8 | ENV PATH=/root/.dotnet/tools:$DOTNET_ROOT:$PATH \ 9 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 10 | AWS_EXECUTION_ENV=AWS_Lambda_dotnetcore2.1 \ 11 | DOTNET_SDK_VERSION=2.1.803 \ 12 | DOTNET_CLI_TELEMETRY_OPTOUT=1 \ 13 | NUGET_XMLDOC_MODE=skip 14 | 15 | COPY --from=0 /var/runtime /var/runtime 16 | COPY --from=0 /var/lang /var/lang 17 | COPY --from=0 /var/rapid /var/rapid 18 | 19 | RUN yum install -y libunwind && \ 20 | curl -L https://dot.net/v1/dotnet-install.sh | bash -s -- -v $DOTNET_SDK_VERSION -i $DOTNET_ROOT && \ 21 | mkdir /tmp/warmup && \ 22 | cd /tmp/warmup && \ 23 | dotnet new && \ 24 | cd / && \ 25 | rm -rf /tmp/warmup /tmp/NuGetScratch /tmp/.dotnet 26 | 27 | # Add these as a separate layer as they get updated frequently 28 | # The pipx workaround is due to https://github.com/pipxproject/pipx/issues/218 29 | RUN source /usr/local/pipx/shared/bin/activate && \ 30 | pipx install virtualenv && \ 31 | pipx install pipenv && \ 32 | pipx install awscli==1.* && \ 33 | pipx install aws-lambda-builders==1.2.0 && \ 34 | pipx install aws-sam-cli==1.15.0 && \ 35 | dotnet tool install --global Amazon.Lambda.Tools --version 3.3.1 36 | 37 | CMD ["dotnet", "build"] 38 | -------------------------------------------------------------------------------- /dotnetcore2.1/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:2.1-sdk 2 | WORKDIR /source 3 | 4 | # cache restore result 5 | COPY MockBootstraps/*.csproj . 6 | RUN dotnet restore 7 | 8 | # copy the rest of the code 9 | COPY MockBootstraps/ . 10 | RUN dotnet publish --output /app/ --configuration Release 11 | 12 | 13 | FROM lambci/lambda:provided 14 | 15 | 16 | FROM lambci/lambda-base 17 | 18 | ENV PATH=/var/lang/bin:$PATH \ 19 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 20 | AWS_EXECUTION_ENV=AWS_Lambda_dotnetcore2.1 21 | 22 | RUN rm -rf /var/runtime /var/lang && \ 23 | curl https://lambci.s3.amazonaws.com/fs/dotnetcore2.1.tgz | tar -zx -C / 24 | 25 | COPY --from=0 /app/MockBootstraps.* /var/runtime/ 26 | 27 | COPY --from=1 /var/runtime/init /var/runtime/mockserver 28 | 29 | USER sbx_user1051 30 | 31 | ENTRYPOINT ["/var/lang/bin/dotnet", "/var/runtime/MockBootstraps.dll"] 32 | -------------------------------------------------------------------------------- /dotnetcore2.1/run/MockBootstraps/DebuggerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading.Tasks; 4 | 5 | namespace MockLambdaRuntime 6 | { 7 | internal static class DebuggerExtensions 8 | { 9 | /// 10 | /// Tries to wait for the debugger to attach by inspecting property in a loop. 11 | /// 12 | /// representing the frequency of inspection. 13 | /// representing the timeout for the operation. 14 | /// True if debugger was attached, false if timeout occured. 15 | public static bool TryWaitForAttaching(TimeSpan queryInterval, TimeSpan timeout) 16 | { 17 | var stopwatch = Stopwatch.StartNew(); 18 | 19 | while (!Debugger.IsAttached) 20 | { 21 | if (stopwatch.Elapsed > timeout) 22 | { 23 | return false; 24 | } 25 | 26 | Task.Delay(queryInterval).Wait(); 27 | } 28 | 29 | return true; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /dotnetcore2.1/run/MockBootstraps/MockBootstraps.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | MockLambdaRuntime 7 | true 8 | 9 | 10 | 11 | 12 | lib\Bootstrap.dll 13 | 14 | 15 | lib\Amazon.Lambda.Core.dll 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /dotnetcore2.1/run/MockBootstraps/MockBootstraps.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2017 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockBootstraps", "MockBootstraps.csproj", "{8AD9356B-231B-4B42-B168-D06497B769AF}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {8AD9356B-231B-4B42-B168-D06497B769AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {8AD9356B-231B-4B42-B168-D06497B769AF}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {8AD9356B-231B-4B42-B168-D06497B769AF}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {8AD9356B-231B-4B42-B168-D06497B769AF}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | EndGlobal 18 | -------------------------------------------------------------------------------- /dotnetcore2.1/run/MockBootstraps/MockLambdaContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace MockLambdaRuntime 7 | { 8 | public class MockLambdaContext 9 | { 10 | static readonly Random random = new Random(); 11 | 12 | /// Creates a mock context from a given Lambda handler and event 13 | public MockLambdaContext(string handler, string eventBody) 14 | { 15 | RequestId = Guid.NewGuid().ToString(); 16 | StartTime = DateTime.Now; 17 | Body = eventBody; 18 | Timeout = Convert.ToInt32(EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_TIMEOUT", "300")); 19 | MemorySize = Convert.ToInt32(EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", "1536")); 20 | FunctionName = EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_NAME", "test"); 21 | FunctionVersion = EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_VERSION", "$LATEST"); 22 | LogGroup = EnvHelper.GetOrDefault("AWS_LAMBDA_LOG_GROUP_NAME", $"/aws/lambda/{FunctionName}"); 23 | LogStream = EnvHelper.GetOrDefault("AWS_LAMBDA_LOG_STREAM_NAME", RandomLogStreamName); 24 | Region = EnvHelper.GetOrDefault("AWS_REGION", EnvHelper.GetOrDefault("AWS_DEFAULT_REGION", "us-east-1")); 25 | AccountId = EnvHelper.GetOrDefault("AWS_ACCOUNT_ID", "000000000000"); 26 | Arn = EnvHelper.GetOrDefault("AWS_LAMBDA_FUNCTION_INVOKED_ARN", $"arn:aws:lambda:{Region}:{AccountId}:function:{FunctionName}"); 27 | StayOpen = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOCKER_LAMBDA_STAY_OPEN")); 28 | 29 | Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME", FunctionName); 30 | Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_VERSION", FunctionVersion); 31 | Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", MemorySize.ToString()); 32 | Environment.SetEnvironmentVariable("AWS_LAMBDA_LOG_GROUP_NAME", LogGroup); 33 | Environment.SetEnvironmentVariable("AWS_LAMBDA_LOG_STREAM_NAME", LogStream); 34 | Environment.SetEnvironmentVariable("AWS_REGION", Region); 35 | Environment.SetEnvironmentVariable("AWS_DEFAULT_REGION", Region); 36 | Environment.SetEnvironmentVariable("_HANDLER", handler); 37 | } 38 | 39 | /// Calculates the remaining time using current time and timeout 40 | public TimeSpan RemainingTime() 41 | { 42 | return StartTime + TimeSpan.FromSeconds(Timeout) - DateTime.Now; 43 | } 44 | 45 | public long DeadlineMs 46 | { 47 | set 48 | { 49 | Timeout = (int)DateTimeOffset.FromUnixTimeMilliseconds(value).Subtract(DateTime.Now).TotalSeconds; 50 | } 51 | } 52 | 53 | public string Body 54 | { 55 | set 56 | { 57 | InputStream = new MemoryStream(); 58 | var eventData = Encoding.UTF8.GetBytes(value); 59 | InputStream.Write(eventData, 0, eventData.Length); 60 | InputStream.Position = 0; 61 | } 62 | } 63 | 64 | public Stream InputStream { get; set; } 65 | 66 | public string RequestId { get; set; } 67 | public DateTime StartTime { get; set; } 68 | 69 | public int Timeout { get; set; } 70 | 71 | public int MemorySize { get; set; } 72 | 73 | public string FunctionName { get; set; } 74 | 75 | public string FunctionVersion { get; set; } 76 | 77 | public string LogGroup { get; set; } 78 | 79 | public string LogStream { get; set; } 80 | 81 | public string Region { get; set; } 82 | 83 | public string AccountId { get; set; } 84 | 85 | public string Arn { get; set; } 86 | 87 | public bool StayOpen { get; } 88 | 89 | string RandomLogStreamName => $"{DateTime.Now.ToString("yyyy/MM/dd")}/[{FunctionVersion}]{random.Next().ToString("x") + random.Next().ToString("x")}"; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /dotnetcore2.1/run/MockBootstraps/lib/Amazon.Lambda.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambci/docker-lambda/de9a2bf5b73f6330fff10e0203f94b9f6f784ab6/dotnetcore2.1/run/MockBootstraps/lib/Amazon.Lambda.Core.dll -------------------------------------------------------------------------------- /dotnetcore2.1/run/MockBootstraps/lib/Bootstrap.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambci/docker-lambda/de9a2bf5b73f6330fff10e0203f94b9f6f784ab6/dotnetcore2.1/run/MockBootstraps/lib/Bootstrap.dll -------------------------------------------------------------------------------- /dotnetcore2.1/run/MockBootstraps/lib/Bootstrap.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambci/docker-lambda/de9a2bf5b73f6330fff10e0203f94b9f6f784ab6/dotnetcore2.1/run/MockBootstraps/lib/Bootstrap.pdb -------------------------------------------------------------------------------- /dotnetcore2.1/run/update_libs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | curl https://lambci.s3.amazonaws.com/fs/dotnetcore2.1.tgz | \ 4 | tar -xz var/runtime/Amazon.Lambda.Core.dll var/runtime/Bootstrap.dll var/runtime/Bootstrap.pdb 5 | 6 | mv ./var/runtime/*.dll ./var/runtime/*.pdb ./MockBootstraps/lib/ 7 | rm -rf ./var 8 | -------------------------------------------------------------------------------- /dotnetcore3.1/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:dotnetcore3.1 2 | 3 | FROM lambci/lambda-base-2:build 4 | 5 | # Run: docker run --rm --entrypoint dotnet lambci/lambda:dotnetcore3.1 --info 6 | # Check https://dotnet.microsoft.com/download/dotnet-core/3.1 for versions 7 | ENV DOTNET_ROOT=/var/lang/bin 8 | ENV PATH=/root/.dotnet/tools:$DOTNET_ROOT:$PATH \ 9 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 10 | AWS_EXECUTION_ENV=AWS_Lambda_dotnetcore3.1 \ 11 | DOTNET_SDK_VERSION=3.1.405 \ 12 | DOTNET_CLI_TELEMETRY_OPTOUT=1 \ 13 | NUGET_XMLDOC_MODE=skip 14 | 15 | COPY --from=0 /var/runtime /var/runtime 16 | COPY --from=0 /var/lang /var/lang 17 | COPY --from=0 /var/rapid /var/rapid 18 | 19 | RUN curl -L https://dot.net/v1/dotnet-install.sh | bash -s -- -v $DOTNET_SDK_VERSION -i $DOTNET_ROOT && \ 20 | mkdir /tmp/warmup && \ 21 | cd /tmp/warmup && \ 22 | dotnet new && \ 23 | cd / && \ 24 | rm -rf /tmp/warmup /tmp/NuGetScratch /tmp/.dotnet 25 | 26 | # Add these as a separate layer as they get updated frequently 27 | RUN pipx install awscli==1.* && \ 28 | pipx install aws-lambda-builders==1.2.0 && \ 29 | pipx install aws-sam-cli==1.15.0 && \ 30 | dotnet tool install --global Amazon.Lambda.Tools --version 4.0.0 31 | 32 | CMD ["dotnet", "build"] 33 | -------------------------------------------------------------------------------- /dotnetcore3.1/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base 2 | 3 | RUN curl https://lambci.s3.amazonaws.com/fs/dotnetcore3.1.tgz | tar -zx -C /opt 4 | 5 | 6 | FROM lambci/lambda:provided 7 | 8 | 9 | FROM lambci/lambda-base-2 10 | 11 | ENV PATH=/var/lang/bin:$PATH \ 12 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 13 | AWS_EXECUTION_ENV=AWS_Lambda_dotnetcore3.1 14 | 15 | COPY --from=0 /opt/* /var/ 16 | 17 | COPY --from=1 /var/runtime/init /var/rapid/init 18 | 19 | USER sbx_user1051 20 | 21 | ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"] 22 | -------------------------------------------------------------------------------- /examples/docker-file/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:nodejs8.10 2 | 3 | ENV AWS_LAMBDA_FUNCTION_NAME=docker-build \ 4 | AWS_LAMBDA_FUNCTION_VERSION=2 \ 5 | AWS_LAMBDA_FUNCTION_MEMORY_SIZE=384 \ 6 | AWS_LAMBDA_FUNCTION_TIMEOUT=60 \ 7 | AWS_REGION=us-east-1 8 | 9 | COPY . . 10 | 11 | # If we want to match permissions in /var/task exactly... 12 | USER root 13 | RUN chown -R slicer:497 . 14 | USER sbx_user1051 15 | 16 | -------------------------------------------------------------------------------- /examples/docker-file/index.js: -------------------------------------------------------------------------------- 1 | var execSync = require('child_process').execSync 2 | 3 | // Intended to show that a built image will have the correct permissions in /var/task 4 | // docker build -t build-test . && docker run --rm build-test 5 | 6 | exports.handler = function(event, context, cb) { 7 | 8 | console.log(process.execPath) 9 | console.log(process.execArgv) 10 | console.log(process.argv) 11 | console.log(process.cwd()) 12 | console.log(process.mainModule.filename) 13 | console.log(__filename) 14 | console.log(process.env) 15 | console.log(process.getuid()) 16 | console.log(process.getgid()) 17 | console.log(process.geteuid()) 18 | console.log(process.getegid()) 19 | console.log(process.getgroups()) 20 | console.log(process.umask()) 21 | 22 | console.log(event) 23 | 24 | console.log(context) 25 | 26 | context.callbackWaitsForEmptyEventLoop = false 27 | 28 | console.log(context.getRemainingTimeInMillis()) 29 | 30 | console.log(execSync('ls -l /var/task', {encoding: 'utf8'})) 31 | 32 | cb() 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /examples/docker-file/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docker-build", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "engines" : { 6 | "node" : ">=0.11.12" 7 | }, 8 | "scripts": { 9 | "test": "docker build -t build-test . && docker run --rm build-test" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/dotnetcore2.0/Function.cs: -------------------------------------------------------------------------------- 1 | // Compile with: 2 | // docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.0 dotnet publish -c Release -o pub 3 | 4 | // Run with: 5 | // docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore2.0 test::test.Function::FunctionHandler '{"some": "event"}' 6 | 7 | using System; 8 | using System.Collections; 9 | using Amazon.Lambda.Core; 10 | 11 | [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 12 | 13 | namespace test 14 | { 15 | public class Function 16 | { 17 | public string FunctionHandler(object inputEvent, ILambdaContext context) 18 | { 19 | context.Logger.Log($"inputEvent: {inputEvent}"); 20 | LambdaLogger.Log($"RemainingTime: {context.RemainingTime}"); 21 | 22 | foreach (DictionaryEntry kv in Environment.GetEnvironmentVariables()) 23 | { 24 | context.Logger.Log($"{kv.Key}={kv.Value}"); 25 | } 26 | 27 | return "Hello World!"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/dotnetcore2.0/README.md: -------------------------------------------------------------------------------- 1 | # .NET Core 2.0 docker-lambda example 2 | 3 | ```sh 4 | # Will place the compiled code in `./pub` 5 | docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.0 dotnet publish -c Release -o pub 6 | 7 | # Then you can run using that as the task directory 8 | docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore2.0 test::test.Function::FunctionHandler '{"some": "event"}' 9 | ``` 10 | -------------------------------------------------------------------------------- /examples/dotnetcore2.0/test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/dotnetcore2.1/Function.cs: -------------------------------------------------------------------------------- 1 | // Compile with: 2 | // docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.1 dotnet publish -c Release -o pub 3 | 4 | // Run with: 5 | // docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore2.1 test::test.Function::FunctionHandler '{"some": "event"}' 6 | 7 | using System; 8 | using System.Collections; 9 | using Amazon.Lambda.Core; 10 | 11 | [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 12 | 13 | namespace test 14 | { 15 | public class Function 16 | { 17 | public string FunctionHandler(object inputEvent, ILambdaContext context) 18 | { 19 | context.Logger.Log($"inputEvent: {inputEvent}"); 20 | LambdaLogger.Log($"RemainingTime: {context.RemainingTime}"); 21 | 22 | foreach (DictionaryEntry kv in Environment.GetEnvironmentVariables()) 23 | { 24 | context.Logger.Log($"{kv.Key}={kv.Value}"); 25 | } 26 | 27 | return "Hello World!"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/dotnetcore2.1/README.md: -------------------------------------------------------------------------------- 1 | # .NET Core 2.1 docker-lambda example 2 | 3 | ```sh 4 | # Will place the compiled code in `./pub` 5 | docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.1 dotnet publish -c Release -o pub 6 | 7 | # Then you can run using that as the task directory 8 | docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore2.1 test::test.Function::FunctionHandler '{"some": "event"}' 9 | ``` 10 | -------------------------------------------------------------------------------- /examples/dotnetcore2.1/test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/dotnetcore2.1/test.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test.csproj", "{0A83D120-2336-4F30-86F1-DC045C3C9B90}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {0A83D120-2336-4F30-86F1-DC045C3C9B90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {0A83D120-2336-4F30-86F1-DC045C3C9B90}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {0A83D120-2336-4F30-86F1-DC045C3C9B90}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {0A83D120-2336-4F30-86F1-DC045C3C9B90}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | EndGlobal 18 | -------------------------------------------------------------------------------- /examples/dotnetcore3.1/Function.cs: -------------------------------------------------------------------------------- 1 | // Compile with: 2 | // docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore3.1 dotnet publish -c Release -o pub 3 | 4 | // Run with: 5 | // docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore3.1 test::test.Function::FunctionHandler '{"some": "event"}' 6 | 7 | using System; 8 | using System.Collections; 9 | using Amazon.Lambda.Core; 10 | 11 | [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 12 | 13 | namespace test 14 | { 15 | public class Function 16 | { 17 | public string FunctionHandler(object inputEvent, ILambdaContext context) 18 | { 19 | Console.WriteLine($"inputEvent: {inputEvent}"); 20 | Console.WriteLine($"RemainingTime: {context.RemainingTime}"); 21 | 22 | foreach (DictionaryEntry kv in Environment.GetEnvironmentVariables()) 23 | { 24 | Console.WriteLine($"{kv.Key}={kv.Value}"); 25 | } 26 | 27 | return "Hello World!"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/dotnetcore3.1/README.md: -------------------------------------------------------------------------------- 1 | # .NET Core 3.1 docker-lambda example 2 | 3 | ```sh 4 | # Will place the compiled code in `./pub` 5 | docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore3.1 dotnet publish -c Release -o pub 6 | 7 | # Then you can run using that as the task directory 8 | docker run --rm -v "$PWD"/pub:/var/task lambci/lambda:dotnetcore3.1 test::test.Function::FunctionHandler '{"some": "event"}' 9 | ``` 10 | -------------------------------------------------------------------------------- /examples/dotnetcore3.1/test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/dotnetcore3.1/test.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test.csproj", "{0A83D120-2336-4F30-86F1-DC045C3C9B90}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {0A83D120-2336-4F30-86F1-DC045C3C9B90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {0A83D120-2336-4F30-86F1-DC045C3C9B90}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {0A83D120-2336-4F30-86F1-DC045C3C9B90}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {0A83D120-2336-4F30-86F1-DC045C3C9B90}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | EndGlobal 18 | -------------------------------------------------------------------------------- /examples/go1.x/go.mod: -------------------------------------------------------------------------------- 1 | module handler 2 | 3 | require github.com/aws/aws-lambda-go v1.13.3 4 | 5 | go 1.15 6 | -------------------------------------------------------------------------------- /examples/go1.x/go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/aws/aws-lambda-go v1.13.3 h1:SuCy7H3NLyp+1Mrfp+m80jcbi9KYWAs9/BXwppwRDzY= 3 | github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= 4 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 5 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 7 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 8 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 9 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 10 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 11 | github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 12 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 13 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 14 | -------------------------------------------------------------------------------- /examples/go1.x/handler.go: -------------------------------------------------------------------------------- 1 | // Compile with: 2 | // docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c 'go mod download && go build handler.go' 3 | 4 | // Run with: 5 | // docker run --rm -v "$PWD":/var/task lambci/lambda:go1.x handler '{"Records": []}' 6 | 7 | package main 8 | 9 | import ( 10 | "context" 11 | "fmt" 12 | 13 | "github.com/aws/aws-lambda-go/events" 14 | "github.com/aws/aws-lambda-go/lambda" 15 | ) 16 | 17 | func handleRequest(ctx context.Context, event events.S3Event) (string, error) { 18 | fmt.Println(ctx) 19 | 20 | fmt.Println(event) 21 | 22 | return "Hello World!", nil 23 | } 24 | 25 | func main() { 26 | lambda.Start(handleRequest) 27 | } 28 | -------------------------------------------------------------------------------- /examples/java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | example-handler 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | 25 | 1599680497045 26 | 27 | 30 28 | 29 | org.eclipse.core.resources.regexFilterMatcher 30 | node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /examples/java/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | arguments= 2 | auto.sync=false 3 | build.scans.enabled=false 4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3)) 5 | connection.project.dir= 6 | eclipse.preferences.version=1 7 | gradle.user.home= 8 | java.home= 9 | jvm.arguments= 10 | offline.mode=false 11 | override.workspace.settings=true 12 | show.console.view=true 13 | show.executions.view=true 14 | -------------------------------------------------------------------------------- /examples/java/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | -------------------------------------------------------------------------------- /examples/java/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /examples/java/README.md: -------------------------------------------------------------------------------- 1 | # Java 8 docker-lambda example 2 | 3 | Run with: 4 | 5 | ```sh 6 | # Will place the compiled code in `./build/docker` 7 | docker run --rm -v "$PWD":/app -w /app gradle:6.0 gradle build 8 | 9 | # Then you can run using that directory as the task directory 10 | docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java8 org.lambci.lambda.ExampleHandler '{"some": "event"}' 11 | 12 | # OR 13 | docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java11 org.lambci.lambda.ExampleHandler '{"some": "event"}' 14 | ``` 15 | -------------------------------------------------------------------------------- /examples/java/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | sourceCompatibility = '1.8' 4 | targetCompatibility = '1.8' 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | implementation ( 12 | 'com.amazonaws:aws-lambda-java-core:1.2.0', 13 | 'com.amazonaws:aws-lambda-java-events:2.2.7' 14 | ) 15 | } 16 | 17 | task buildZip(type: Zip) { 18 | from compileJava 19 | from processResources 20 | into('lib') { 21 | from configurations.runtimeClasspath 22 | } 23 | } 24 | 25 | task buildDocker(type: Copy) { 26 | from compileJava 27 | from processResources 28 | into('lib') { 29 | from configurations.runtimeClasspath 30 | } 31 | into 'build/docker' 32 | } 33 | 34 | build.dependsOn buildDocker 35 | -------------------------------------------------------------------------------- /examples/java/src/main/java/org/lambci/lambda/ExampleHandler.java: -------------------------------------------------------------------------------- 1 | // Run with: 2 | // docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java8 org.lambci.lambda.ExampleHandler 3 | 4 | package org.lambci.lambda; 5 | 6 | import java.io.File; 7 | import java.lang.management.ManagementFactory; 8 | import java.util.Map; 9 | 10 | import com.amazonaws.services.lambda.runtime.Context; 11 | import com.amazonaws.services.lambda.runtime.LambdaLogger; 12 | import com.amazonaws.services.lambda.runtime.RequestHandler; 13 | 14 | public class ExampleHandler implements RequestHandler { 15 | 16 | @Override 17 | public String handleRequest(Object input, Context context) { 18 | // throw new RuntimeException("whatever"); 19 | LambdaLogger logger = context.getLogger(); 20 | logger.log(ManagementFactory.getRuntimeMXBean().getInputArguments().toString() + "\n"); 21 | logger.log(System.getProperty("sun.java.command") + "\n"); 22 | logger.log(System.getProperty("java.home") + "\n"); 23 | logger.log(System.getProperty("java.library.path") + "\n"); 24 | logger.log(System.getProperty("java.class.path") + "\n"); 25 | logger.log(System.getProperty("user.dir") + "\n"); 26 | logger.log(System.getProperty("user.home") + "\n"); 27 | logger.log(System.getProperty("user.name") + "\n"); 28 | logger.log(new File(".").getAbsolutePath() + "\n"); 29 | Map env = System.getenv(); 30 | for (String envName : env.keySet()) { 31 | logger.log(envName + "=" + env.get(envName) + "\n"); 32 | } 33 | logger.log(context.getAwsRequestId() + "\n"); 34 | logger.log(context.getFunctionName() + "\n"); 35 | logger.log(context.getFunctionVersion() + "\n"); 36 | logger.log(context.getInvokedFunctionArn() + "\n"); 37 | logger.log(context.getLogGroupName() + "\n"); 38 | logger.log(context.getLogStreamName() + "\n"); 39 | if (context.getIdentity() != null) { 40 | logger.log(context.getIdentity().getIdentityId() + "\n"); 41 | logger.log(context.getIdentity().getIdentityPoolId() + "\n"); 42 | } 43 | logger.log(context.getClientContext() + "\n"); 44 | logger.log(context.getMemoryLimitInMB() + "\n"); 45 | logger.log(context.getRemainingTimeInMillis() + "\n"); 46 | logger.log(input + "\n"); 47 | return "Hello World!"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/nodejs-native-module/index.js: -------------------------------------------------------------------------------- 1 | var bcrypt = require('bcrypt') 2 | 3 | // Hashed password for "lamda-docker" 4 | var HASHED_PASS = '$2a$10$w9.BRCsnWXv5f.eUGD2fieT.wfLV9.rSJFC/2bzz3sahJdCLaYs0K' 5 | 6 | exports.handler = function(event, context, cb) { 7 | console.log('hello?') 8 | bcrypt.compare(event.password, HASHED_PASS, function(err, res) { 9 | cb(err, res ? 'Matches!' : 'NopeNopeNope') 10 | }) 11 | } 12 | 13 | // Just to test this locally: 14 | if (require.main === module) { 15 | exports.handler({password: 'lambda-docker'}, {}, console.log) 16 | exports.handler({password: 'lambda-mocker'}, {}, console.log) 17 | } 18 | -------------------------------------------------------------------------------- /examples/nodejs-native-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-native", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "build": "docker run --rm -v \"$PWD\":/var/task lambci/lambda:build-nodejs12.x npm rebuild --build-from-source", 7 | "test": "node test.js" 8 | }, 9 | "dependencies": { 10 | "bcrypt": "^5.0.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/nodejs-native-module/test.js: -------------------------------------------------------------------------------- 1 | var dockerLambda = require('../..') 2 | 3 | var match = dockerLambda({ event: { password: 'lambda-docker' }, dockerImage: 'lambci/lambda:nodejs12.x' }) 4 | 5 | console.log(match === 'Matches!' ? 'Match Passed' : 'Match Failed: ' + match) 6 | 7 | var nonMatch = dockerLambda({ event: { password: 'lambda-mocker' }, dockerImage: 'lambci/lambda:nodejs12.x' }) 8 | 9 | console.log(nonMatch === 'NopeNopeNope' ? 'Non-Match Passed' : 'Non-Match Failed: ' + nonMatch) 10 | -------------------------------------------------------------------------------- /examples/nodejs6.10/index.js: -------------------------------------------------------------------------------- 1 | // Just a test lambda, run with: 2 | // docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs4.3 3 | // OR 4 | // docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs6.10 5 | // OR 6 | // docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs8.10 7 | 8 | exports.handler = function(event, context, cb) { 9 | 10 | console.log(process.execPath) 11 | console.log(process.execArgv) 12 | console.log(process.argv) 13 | console.log(process.cwd()) 14 | console.log(process.mainModule.filename) 15 | console.log(__filename) 16 | console.log(process.env) 17 | console.log(process.getuid()) 18 | console.log(process.getgid()) 19 | console.log(process.geteuid()) 20 | console.log(process.getegid()) 21 | console.log(process.getgroups()) 22 | console.log(process.umask()) 23 | 24 | console.log(event) 25 | 26 | console.log(context) 27 | 28 | context.callbackWaitsForEmptyEventLoop = false 29 | 30 | console.log(context.getRemainingTimeInMillis()) 31 | 32 | cb() 33 | } 34 | 35 | -------------------------------------------------------------------------------- /examples/nodejs6.10/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docker-run", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "docker run --rm -v \"$PWD\":/var/task lambci/lambda:nodejs6.10 index.handler '{\"some\": \"event\"}'" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/nodejs8.10/index.js: -------------------------------------------------------------------------------- 1 | // Just a test lambda, run with: 2 | // docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs8.10 3 | 4 | exports.handler = async(event, context) => { 5 | console.log(process.execPath) 6 | console.log(process.execArgv) 7 | console.log(process.argv) 8 | console.log(process.cwd()) 9 | console.log(process.mainModule.filename) 10 | console.log(__filename) 11 | console.log(process.env) 12 | console.log(process.getuid()) 13 | console.log(process.getgid()) 14 | console.log(process.geteuid()) 15 | console.log(process.getegid()) 16 | console.log(process.getgroups()) 17 | console.log(process.umask()) 18 | 19 | console.log(event) 20 | 21 | console.log(context) 22 | 23 | context.callbackWaitsForEmptyEventLoop = false 24 | 25 | console.log(context.getRemainingTimeInMillis()) 26 | } 27 | -------------------------------------------------------------------------------- /examples/nodejs8.10/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docker-run", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "docker run --rm -v \"$PWD\":/var/task lambci/lambda:nodejs8.10 index.handler '{\"some\": \"event\"}'" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/post.lua: -------------------------------------------------------------------------------- 1 | -- Run with: 2 | -- wrk -s post.lua 'http://localhost:9001/2015-03-31/functions/myfunction/invocations' 3 | wrk.method = "POST" 4 | wrk.body = "{}" 5 | wrk.headers["Content-Type"] = "application/json" 6 | -------------------------------------------------------------------------------- /examples/provided.al2/bootstrap.go: -------------------------------------------------------------------------------- 1 | // Compile with: 2 | // docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x sh -c 'go mod download && go build -tags lambda.norpc bootstrap.go' 3 | 4 | // Run with: 5 | // docker run --rm -v "$PWD":/var/task lambci/lambda:provided.al2 handler '{"Records": []}' 6 | 7 | package main 8 | 9 | import ( 10 | "context" 11 | "fmt" 12 | 13 | "github.com/aws/aws-lambda-go/events" 14 | "github.com/aws/aws-lambda-go/lambda" 15 | ) 16 | 17 | func handleRequest(ctx context.Context, event events.S3Event) (string, error) { 18 | fmt.Println(ctx) 19 | 20 | fmt.Println(event) 21 | 22 | return "Hello World!", nil 23 | } 24 | 25 | func main() { 26 | lambda.Start(handleRequest) 27 | } 28 | -------------------------------------------------------------------------------- /examples/provided.al2/go.mod: -------------------------------------------------------------------------------- 1 | module bootstrap 2 | 3 | require ( 4 | github.com/aws/aws-lambda-go v1.19.0 5 | github.com/aws/aws-sdk-go-v2 v0.24.0 6 | ) 7 | 8 | go 1.15 9 | -------------------------------------------------------------------------------- /examples/provided.al2/go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/aws/aws-lambda-go v1.19.0 h1:Cn28zA8Mic4NpR7p4IlaEW2srI+U3+I7tRqjFMpt/fs= 3 | github.com/aws/aws-lambda-go v1.19.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU= 4 | github.com/aws/aws-sdk-go-v2 v0.24.0/go.mod h1:2LhT7UgHOXK3UXONKI5OMgIyoQL6zTAw/jwIeX6yqzw= 5 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 6 | github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 9 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 10 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 11 | github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= 12 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 13 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 14 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 15 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 16 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 17 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 18 | github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= 19 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 20 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 21 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 22 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 23 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 24 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 25 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 26 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 27 | gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 28 | -------------------------------------------------------------------------------- /examples/provided/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # docker run --rm -v $PWD:/var/task lambci/lambda:provided handler '{"some": "event"}' 4 | 5 | while true 6 | do 7 | HEADERS="$(mktemp)" 8 | 9 | EVENT_DATA=$(curl -v -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next") 10 | INVOCATION_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2) 11 | 12 | echo "Invoke received. Request ID: ${INVOCATION_ID}. Event:" 13 | echo $EVENT_DATA 14 | 15 | RESPONSE="Hello from Lambda!" 16 | 17 | curl -v "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$INVOCATION_ID/response" -d "$RESPONSE" 18 | done 19 | -------------------------------------------------------------------------------- /examples/python/lambda_function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import os 3 | import sys 4 | import subprocess 5 | 6 | # Just a test lambda, run with: 7 | # docker run --rm -v "$PWD":/var/task lambci/lambda:python2.7 8 | # OR 9 | # docker run --rm -v "$PWD":/var/task lambci/lambda:python3.6 10 | # OR 11 | # docker run --rm -v "$PWD":/var/task lambci/lambda:python3.7 lambda_function.lambda_handler 12 | 13 | def lambda_handler(event, context): 14 | context.log('Hello!') 15 | context.log('Hmmm, does not add newlines in 3.7?') 16 | context.log('\n') 17 | 18 | print(sys.executable) 19 | print(sys.argv) 20 | print(os.getcwd()) 21 | print(__file__) 22 | print(os.environ) 23 | print(context.__dict__) 24 | 25 | return { 26 | "executable": str(sys.executable), 27 | "sys.argv": str(sys.argv), 28 | "os.getcwd": str(os.getcwd()), 29 | "__file__": str(__file__), 30 | "os.environ": str(os.environ), 31 | "context.__dict__": str(context.__dict__), 32 | "event": event 33 | } 34 | -------------------------------------------------------------------------------- /examples/ruby/lambda_function.rb: -------------------------------------------------------------------------------- 1 | require 'pp' 2 | 3 | # docker run --rm -v "$PWD":/var/task lambci/lambda:ruby2.5 lambda_function.lambda_handler 4 | # docker run --rm -v "$PWD":/var/task lambci/lambda:ruby2.7 lambda_function.lambda_handler 5 | 6 | def lambda_handler(event:, context:) 7 | info = { 8 | 'event' => event, 9 | 'ENV' => ENV.to_hash, 10 | 'context' => context.instance_variables.each_with_object({}) { |k, h| h[k] = context.instance_variable_get k }, 11 | 'ps aux' => `bash -O extglob -c 'for cmd in /proc/+([0-9])/cmdline; do echo $cmd; xargs -n 1 -0 < $cmd; done'`, 12 | 'proc environ' => `xargs -n 1 -0 < /proc/1/environ`, 13 | } 14 | 15 | pp info 16 | 17 | return info 18 | end 19 | -------------------------------------------------------------------------------- /examples/terminal3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambci/docker-lambda/de9a2bf5b73f6330fff10e0203f94b9f6f784ab6/examples/terminal3.png -------------------------------------------------------------------------------- /go1.x/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:go1.x 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | # https://golang.org/doc/devel/release.html 6 | ENV GOLANG_VERSION=1.15 \ 7 | GOPATH=/go \ 8 | PATH=/go/bin:/usr/local/go/bin:$PATH \ 9 | AWS_EXECUTION_ENV=AWS_Lambda_go1.x 10 | 11 | WORKDIR /go/src/handler 12 | 13 | COPY --from=0 /var/runtime /var/runtime 14 | COPY --from=0 /var/lang /var/lang 15 | COPY --from=0 /var/rapid /var/rapid 16 | 17 | RUN curl https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz | tar -zx -C /usr/local && \ 18 | go get github.com/golang/dep/cmd/dep && \ 19 | go install github.com/golang/dep/cmd/dep && \ 20 | go get golang.org/x/vgo 21 | 22 | # Add these as a separate layer as they get updated frequently 23 | # The pipx workaround is due to https://github.com/pipxproject/pipx/issues/218 24 | RUN source /usr/local/pipx/shared/bin/activate && \ 25 | pipx install awscli==1.* && \ 26 | pipx install aws-lambda-builders==1.2.0 && \ 27 | pipx install aws-sam-cli==1.15.0 28 | 29 | CMD ["dep", "ensure"] 30 | -------------------------------------------------------------------------------- /go1.x/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1 2 | WORKDIR /app 3 | COPY go.mod go.sum ./ 4 | RUN go mod download 5 | COPY aws-lambda-mock.go ./ 6 | RUN GOARCH=amd64 GOOS=linux go build aws-lambda-mock.go 7 | 8 | 9 | FROM lambci/lambda:provided 10 | 11 | 12 | FROM lambci/lambda-base 13 | 14 | ENV AWS_EXECUTION_ENV=AWS_Lambda_go1.x 15 | 16 | RUN rm -rf /var/runtime /var/lang && \ 17 | curl https://lambci.s3.amazonaws.com/fs/go1.x.tgz | tar -zx -C / 18 | 19 | COPY --from=0 /app/aws-lambda-mock /var/runtime/aws-lambda-go 20 | 21 | COPY --from=1 /var/runtime/init /var/runtime/mockserver 22 | 23 | USER sbx_user1051 24 | 25 | ENTRYPOINT ["/var/runtime/aws-lambda-go"] 26 | -------------------------------------------------------------------------------- /go1.x/run/go.mod: -------------------------------------------------------------------------------- 1 | module aws-lambda-mock 2 | 3 | require github.com/aws/aws-lambda-go v1.13.3 4 | 5 | go 1.15 6 | -------------------------------------------------------------------------------- /go1.x/run/go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/aws/aws-lambda-go v1.13.2 h1:8lYuRVn6rESoUNZXdbCmtGB4bBk4vcVYojiHjE4mMrM= 3 | github.com/aws/aws-lambda-go v1.13.2/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= 4 | github.com/aws/aws-lambda-go v1.13.3 h1:SuCy7H3NLyp+1Mrfp+m80jcbi9KYWAs9/BXwppwRDzY= 5 | github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= 6 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 9 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 10 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 11 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 12 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 13 | github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 14 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 15 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 16 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var spawnSync = require('child_process').spawnSync 2 | 3 | var ENV_VARS = [ 4 | 'AWS_REGION', 5 | 'AWS_DEFAULT_REGION', 6 | 'AWS_ACCOUNT_ID', 7 | 'AWS_ACCESS_KEY_ID', 8 | 'AWS_SECRET_ACCESS_KEY', 9 | 'AWS_SESSION_TOKEN', 10 | 'AWS_LAMBDA_FUNCTION_NAME', 11 | 'AWS_LAMBDA_FUNCTION_VERSION', 12 | 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE', 13 | 'AWS_LAMBDA_FUNCTION_TIMEOUT', 14 | 'AWS_LAMBDA_FUNCTION_HANDLER', 15 | 'AWS_LAMBDA_EVENT_BODY', 16 | 'DOCKER_LAMBDA_USE_STDIN', 17 | ] 18 | var ENV_ARGS = [].concat.apply([], ENV_VARS.map(function(x) { return ['-e', x] })) 19 | 20 | // Will spawn `docker run` synchronously and return stdout 21 | module.exports = function runSync(options) { 22 | options = options || {} 23 | var dockerImage = options.dockerImage || 'lambci/lambda:nodejs4.3' 24 | var handler = options.handler || 'index.handler' 25 | var event = options.event || {} 26 | var taskDir = options.taskDir == null ? process.cwd() : options.taskDir 27 | var cleanUp = options.cleanUp == null ? true : options.cleanUp 28 | var addEnvVars = options.addEnvVars || false 29 | var dockerArgs = options.dockerArgs || [] 30 | var spawnOptions = options.spawnOptions || {encoding: 'utf8'} 31 | var returnSpawnResult = options.returnSpawnResult || false 32 | 33 | var args = ['run'] 34 | .concat(taskDir ? ['-v', taskDir + ':/var/task'] : []) 35 | .concat(cleanUp ? ['--rm'] : []) 36 | .concat(addEnvVars ? ENV_ARGS : []) 37 | .concat(dockerArgs) 38 | .concat([dockerImage, handler, JSON.stringify(event)]) 39 | 40 | var spawnResult = spawnSync('docker', args, spawnOptions) 41 | 42 | if (returnSpawnResult) { 43 | return spawnResult 44 | } 45 | 46 | if (spawnResult.error || spawnResult.status !== 0) { 47 | var err = spawnResult.error 48 | if (!err) { 49 | err = new Error(spawnResult.stdout || spawnResult.stderr) 50 | err.code = spawnResult.status 51 | err.stdout = spawnResult.stdout 52 | err.stderr = spawnResult.stderr 53 | } 54 | throw err 55 | } 56 | 57 | // If stdio is inherited, stdout/stderr will be null 58 | if (spawnResult.stdout == null) return null 59 | 60 | var stdout = spawnResult.stdout.trim().split('\n') 61 | try { 62 | return JSON.parse(stdout[stdout.length - 1]) 63 | } catch (err) { 64 | // This should return undefined and not null to indicate that either the 65 | // Lambda function had not output or the output could not be parsed. Both 66 | // cases should be rare and are most likely the result of an issue with the 67 | // Lambda function. 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /java11/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:java11 2 | 3 | FROM lambci/lambda-base-2:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_java11 8 | 9 | COPY --from=0 /var/runtime /var/runtime 10 | COPY --from=0 /var/lang /var/lang 11 | COPY --from=0 /var/rapid /var/rapid 12 | 13 | RUN mkdir /usr/local/gradle && curl -L -o gradle.zip https://services.gradle.org/distributions/gradle-6.8.1-bin.zip && \ 14 | unzip -qd /usr/local/gradle gradle.zip && rm gradle.zip && mkdir /usr/local/maven && \ 15 | curl -L http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz | \ 16 | tar -zx -C /usr/local/maven 17 | 18 | ENV PATH="/usr/local/gradle/gradle-6.8.1/bin:/usr/local/maven/apache-maven-3.6.3/bin:${PATH}" 19 | 20 | # Add these as a separate layer as they get updated frequently 21 | RUN pipx install awscli==1.* && \ 22 | pipx install aws-lambda-builders==1.2.0 && \ 23 | pipx install aws-sam-cli==1.15.0 24 | -------------------------------------------------------------------------------- /java11/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base 2 | 3 | RUN curl https://lambci.s3.amazonaws.com/fs/java11.tgz | tar -zx -C /opt 4 | 5 | 6 | FROM lambci/lambda:provided 7 | 8 | 9 | FROM lambci/lambda-base-2 10 | 11 | ENV PATH=/var/lang/bin:$PATH \ 12 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 13 | AWS_EXECUTION_ENV=AWS_Lambda_java11 14 | 15 | COPY --from=0 /opt/* /var/ 16 | 17 | COPY --from=1 /var/runtime/init /var/rapid/init 18 | 19 | USER sbx_user1051 20 | 21 | ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"] 22 | 23 | -------------------------------------------------------------------------------- /java8.al2/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:java8.al2 2 | 3 | FROM lambci/lambda-base-2:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_rapid 8 | 9 | COPY --from=0 /var/runtime /var/runtime 10 | COPY --from=0 /var/lang /var/lang 11 | COPY --from=0 /var/rapid /var/rapid 12 | 13 | RUN rm -rf /var/lang/* && \ 14 | curl -sSL https://corretto.aws/downloads/resources/8.265.01.1/amazon-corretto-8.265.01.1-linux-x64.tar.gz | tar -xz --strip-components=1 -C /var/lang && \ 15 | rm -rf /var/lang/*.zip && \ 16 | mkdir /usr/local/gradle && curl -L -o gradle.zip https://services.gradle.org/distributions/gradle-6.8.1-bin.zip && \ 17 | unzip -qd /usr/local/gradle gradle.zip && rm gradle.zip && mkdir /usr/local/maven && \ 18 | curl -L http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz | \ 19 | tar -zx -C /usr/local/maven 20 | 21 | ENV PATH="/usr/local/gradle/gradle-6.8.1/bin:/usr/local/maven/apache-maven-3.6.3/bin:${PATH}" 22 | 23 | # Add these as a separate layer as they get updated frequently 24 | RUN pipx install awscli==1.* && \ 25 | pipx install aws-lambda-builders==1.2.0 && \ 26 | pipx install aws-sam-cli==1.15.0 27 | -------------------------------------------------------------------------------- /java8.al2/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base 2 | 3 | RUN curl https://lambci.s3.amazonaws.com/fs/java8.al2.tgz | tar -zx -C /opt 4 | 5 | 6 | FROM lambci/lambda:provided 7 | 8 | 9 | FROM lambci/lambda-base-2 10 | 11 | ENV PATH=/var/lang/bin:$PATH \ 12 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 13 | AWS_EXECUTION_ENV=AWS_Lambda_rapid 14 | 15 | COPY --from=0 /opt/* /var/ 16 | 17 | COPY --from=1 /var/runtime/init /var/rapid/init 18 | 19 | USER sbx_user1051 20 | 21 | ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"] 22 | -------------------------------------------------------------------------------- /java8/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:java8 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | ENV AWS_EXECUTION_ENV=AWS_Lambda_java8 6 | 7 | WORKDIR / 8 | 9 | COPY --from=0 /var/runtime /var/runtime 10 | COPY --from=0 /var/lang /var/lang 11 | COPY --from=0 /var/rapid /var/rapid 12 | 13 | RUN yum install -y java-1.8.0-openjdk-devel && \ 14 | mkdir /usr/local/gradle && curl -L -o gradle.zip https://services.gradle.org/distributions/gradle-6.8.1-bin.zip && \ 15 | unzip -qd /usr/local/gradle gradle.zip && rm gradle.zip && mkdir /usr/local/maven && \ 16 | curl -L http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz | \ 17 | tar -zx -C /usr/local/maven 18 | 19 | ENV PATH="/usr/local/gradle/gradle-6.8.1/bin:/usr/local/maven/apache-maven-3.6.3/bin:${PATH}" 20 | 21 | # Add these as a separate layer as they get updated frequently 22 | # The pipx workaround is due to https://github.com/pipxproject/pipx/issues/218 23 | RUN source /usr/local/pipx/shared/bin/activate && \ 24 | pipx install awscli==1.* && \ 25 | pipx install aws-lambda-builders==1.2.0 && \ 26 | pipx install aws-sam-cli==1.15.0 27 | -------------------------------------------------------------------------------- /java8/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-alpine 2 | WORKDIR /src 3 | COPY ./lambda-runtime-mock /src 4 | RUN apk add --no-cache curl && ./build.sh 5 | 6 | 7 | FROM lambci/lambda:provided 8 | 9 | 10 | FROM lambci/lambda-base 11 | 12 | ENV AWS_EXECUTION_ENV=AWS_Lambda_java8 13 | 14 | RUN rm -rf /var/runtime /var/lang && \ 15 | curl https://lambci.s3.amazonaws.com/fs/java8.tgz | tar -zx -C / 16 | 17 | COPY --from=0 /src/LambdaSandboxJava-1.0.jar /var/runtime/lib/ 18 | 19 | COPY --from=1 /var/runtime/init /var/runtime/mockserver 20 | 21 | WORKDIR / 22 | 23 | USER sbx_user1051 24 | 25 | ENTRYPOINT ["/usr/bin/java", "-XX:MaxHeapSize=2834432k", "-XX:MaxMetaspaceSize=163840k", "-XX:ReservedCodeCacheSize=81920k", \ 26 | "-XX:+UseSerialGC", "-Xshare:on", "-XX:-TieredCompilation", "-Djava.net.preferIPv4Stack=true", \ 27 | "-jar", "/var/runtime/lib/LambdaJavaRTEntry-1.0.jar"] 28 | -------------------------------------------------------------------------------- /java8/run/README.md: -------------------------------------------------------------------------------- 1 | # Java 8 Build Instructions 2 | 3 | As the Java 8 Lambda libraries are statically compiled into jars, it's not 4 | possible to just swap in a mock interface source file, as it is in the other 5 | dynamic runtimes, without compiling first. 6 | 7 | The `Dockerfile` here will build using a patched `LambdaSandboxJava-1.0.jar`, 8 | which is checked into git. This jar was built using the jar from the Lambda runtime, 9 | `/var/runtime/lib/LambdaSandboxJava-1.0.jar`, with a single class 10 | (`lambdainternal/LambdaRuntime.class`) updated to use local/mock methods 11 | instead of native ones. 12 | 13 | The build script to perform this patch/update is at 14 | [./lambda-runtime-mock/build.sh](./lambda-runtime-mock/build.sh) 15 | -------------------------------------------------------------------------------- /java8/run/lambda-runtime-mock/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /java8/run/lambda-runtime-mock/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | lambda-runtime-mock 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1599680497051 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /java8/run/lambda-runtime-mock/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /java8/run/lambda-runtime-mock/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd $(dirname "$0") 4 | 5 | curl -s https://lambci.s3.amazonaws.com/fs/java8.tgz | tar -zx -- var/runtime/lib 6 | 7 | mv var/runtime/lib/LambdaSandboxJava-1.0.jar var/runtime/lib/gson-*.jar ./ 8 | 9 | mkdir -p ./target/classes 10 | 11 | javac -target 1.8 -cp ./gson-*.jar -d ./target/classes ./src/main/java/lambdainternal/LambdaRuntime.java 12 | 13 | cp -R ./target/classes/lambdainternal ./ 14 | 15 | jar uf LambdaSandboxJava-1.0.jar lambdainternal/LambdaRuntime*.class 16 | 17 | rm -rf ./var ./lambdainternal 18 | -------------------------------------------------------------------------------- /java8/run/lambda-runtime-mock/gson-2.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambci/docker-lambda/de9a2bf5b73f6330fff10e0203f94b9f6f784ab6/java8/run/lambda-runtime-mock/gson-2.3.1.jar -------------------------------------------------------------------------------- /nodejs10.x/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:nodejs10.x 2 | 3 | FROM lambci/lambda-base-2:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs10.x \ 8 | NODE_PATH=/opt/nodejs/node10/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules 9 | 10 | COPY --from=0 /var/runtime /var/runtime 11 | COPY --from=0 /var/lang /var/lang 12 | COPY --from=0 /var/rapid /var/rapid 13 | 14 | # Add these as a separate layer as they get updated frequently 15 | RUN pipx install awscli==1.* && \ 16 | pipx install aws-lambda-builders==1.2.0 && \ 17 | pipx install aws-sam-cli==1.15.0 18 | -------------------------------------------------------------------------------- /nodejs10.x/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base 2 | 3 | RUN curl https://lambci.s3.amazonaws.com/fs/nodejs10.x.tgz | tar -zx -C /opt 4 | 5 | 6 | FROM lambci/lambda:provided 7 | 8 | 9 | FROM lambci/lambda-base-2 10 | 11 | ENV PATH=/var/lang/bin:$PATH \ 12 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 13 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs10.x 14 | 15 | COPY --from=0 /opt/* /var/ 16 | 17 | COPY --from=1 /var/runtime/init /var/rapid/init 18 | 19 | USER sbx_user1051 20 | 21 | ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap"] 22 | -------------------------------------------------------------------------------- /nodejs12.x/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:nodejs12.x 2 | 3 | FROM lambci/lambda-base-2:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs12.x \ 8 | NODE_PATH=/opt/nodejs/node12/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules 9 | 10 | COPY --from=0 /var/runtime /var/runtime 11 | COPY --from=0 /var/lang /var/lang 12 | COPY --from=0 /var/rapid /var/rapid 13 | 14 | # Add these as a separate layer as they get updated frequently 15 | RUN pipx install awscli==1.* && \ 16 | pipx install aws-lambda-builders==1.2.0 && \ 17 | pipx install aws-sam-cli==1.15.0 18 | -------------------------------------------------------------------------------- /nodejs12.x/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base 2 | 3 | RUN curl https://lambci.s3.amazonaws.com/fs/nodejs12.x.tgz | tar -zx -C /opt 4 | 5 | 6 | FROM lambci/lambda:provided 7 | 8 | 9 | FROM lambci/lambda-base-2 10 | 11 | ENV PATH=/var/lang/bin:$PATH \ 12 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 13 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs12.x 14 | 15 | COPY --from=0 /opt/* /var/ 16 | 17 | COPY --from=1 /var/runtime/init /var/rapid/init 18 | 19 | USER sbx_user1051 20 | 21 | ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"] 22 | -------------------------------------------------------------------------------- /nodejs4.3/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:nodejs4.3 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs4.3 \ 8 | NODE_PATH=/var/runtime:/var/task:/var/runtime/node_modules \ 9 | npm_config_unsafe-perm=true 10 | 11 | COPY --from=0 /var/runtime /var/runtime 12 | COPY --from=0 /var/lang /var/lang 13 | COPY --from=0 /var/rapid /var/rapid 14 | 15 | # Add these as a separate layer as they get updated frequently 16 | # The pipx workaround is due to https://github.com/pipxproject/pipx/issues/218 17 | RUN source /usr/local/pipx/shared/bin/activate && \ 18 | pipx install awscli==1.* && \ 19 | pipx install aws-lambda-builders==1.2.0 && \ 20 | pipx install aws-sam-cli==1.15.0 21 | 22 | CMD ["npm", "rebuild"] 23 | -------------------------------------------------------------------------------- /nodejs4.3/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided 2 | 3 | 4 | FROM lambci/lambda-base 5 | 6 | ENV PATH=/var/lang/bin:$PATH \ 7 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 8 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs4.3 \ 9 | NODE_PATH=/var/runtime:/var/task:/var/runtime/node_modules 10 | 11 | RUN rm -rf /var/runtime /var/lang && \ 12 | curl https://lambci.s3.amazonaws.com/fs/nodejs4.3.tgz | tar -zx -C / 13 | 14 | COPY awslambda-mock.js /var/runtime/node_modules/awslambda/build/Release/awslambda.js 15 | 16 | COPY --from=0 /var/runtime/init /var/runtime/mockserver 17 | 18 | USER sbx_user1051 19 | 20 | ENTRYPOINT ["/var/lang/bin/node", "--expose-gc", "--max-executable-size=160", "--max-semi-space-size=150", "--max-old-space-size=2547", \ 21 | "/var/runtime/node_modules/awslambda/index.js"] 22 | 23 | -------------------------------------------------------------------------------- /nodejs6.10/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:nodejs6.10 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs6.10 \ 8 | NODE_PATH=/opt/nodejs/node6/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules:/var/runtime:/var/task:/var/runtime/node_modules \ 9 | npm_config_unsafe-perm=true 10 | 11 | COPY --from=0 /var/runtime /var/runtime 12 | COPY --from=0 /var/lang /var/lang 13 | COPY --from=0 /var/rapid /var/rapid 14 | 15 | # Add these as a separate layer as they get updated frequently 16 | # The pipx workaround is due to https://github.com/pipxproject/pipx/issues/218 17 | RUN source /usr/local/pipx/shared/bin/activate && \ 18 | pipx install awscli==1.* && \ 19 | pipx install aws-lambda-builders==1.2.0 && \ 20 | pipx install aws-sam-cli==1.15.0 21 | 22 | CMD ["npm", "rebuild"] 23 | -------------------------------------------------------------------------------- /nodejs6.10/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided 2 | 3 | 4 | FROM lambci/lambda-base 5 | 6 | ENV PATH=/var/lang/bin:$PATH \ 7 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 8 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs6.10 \ 9 | NODE_PATH=/opt/nodejs/node6/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules:/var/runtime:/var/task:/var/runtime/node_modules 10 | 11 | RUN rm -rf /var/runtime /var/lang && \ 12 | curl https://lambci.s3.amazonaws.com/fs/nodejs6.10.tgz | tar -zx -C / 13 | 14 | COPY awslambda-mock.js /var/runtime/node_modules/awslambda/build/Release/awslambda.js 15 | 16 | COPY --from=0 /var/runtime/init /var/runtime/mockserver 17 | 18 | USER sbx_user1051 19 | 20 | ENTRYPOINT ["/var/lang/bin/node", "--expose-gc", "--max-executable-size=160", "--max-semi-space-size=150", "--max-old-space-size=2547", \ 21 | "/var/runtime/node_modules/awslambda/index.js"] 22 | 23 | -------------------------------------------------------------------------------- /nodejs8.10/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:nodejs8.10 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs8.10 \ 8 | NODE_PATH=/opt/nodejs/node8/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules:/var/runtime:/var/task:/var/runtime/node_modules \ 9 | npm_config_unsafe-perm=true 10 | 11 | COPY --from=0 /var/runtime /var/runtime 12 | COPY --from=0 /var/lang /var/lang 13 | COPY --from=0 /var/rapid /var/rapid 14 | 15 | # Add these as a separate layer as they get updated frequently 16 | # The pipx workaround is due to https://github.com/pipxproject/pipx/issues/218 17 | RUN source /usr/local/pipx/shared/bin/activate && \ 18 | pipx install awscli==1.* && \ 19 | pipx install aws-lambda-builders==1.2.0 && \ 20 | pipx install aws-sam-cli==1.15.0 21 | 22 | CMD ["npm", "rebuild"] 23 | -------------------------------------------------------------------------------- /nodejs8.10/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided 2 | 3 | 4 | FROM lambci/lambda-base 5 | 6 | ENV PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin \ 7 | LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib \ 8 | AWS_EXECUTION_ENV=AWS_Lambda_nodejs8.10 \ 9 | NODE_PATH=/opt/nodejs/node8/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules:/var/runtime:/var/task:/var/runtime/node_modules 10 | 11 | RUN rm -rf /var/runtime /var/lang && \ 12 | curl https://lambci.s3.amazonaws.com/fs/nodejs8.10.tgz | tar -zx -C / 13 | 14 | COPY awslambda-mock.js /var/runtime/node_modules/awslambda/build/Release/awslambda.js 15 | 16 | COPY --from=0 /var/runtime/init /var/runtime/mockserver 17 | 18 | USER sbx_user1051 19 | 20 | ENTRYPOINT ["/var/lang/bin/node", "--expose-gc", "--max-semi-space-size=150", "--max-old-space-size=2707", \ 21 | "/var/runtime/node_modules/awslambda/index.js"] 22 | 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docker-lambda", 3 | "version": "0.15.3", 4 | "description": "A Docker image and test runner that (very closely) mimics the live AWS Lambda environment", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node test.js" 8 | }, 9 | "directories": { 10 | "example": "examples" 11 | }, 12 | "repository": "lambci/docker-lambda", 13 | "author": "Michael Hart ", 14 | "license": "MIT", 15 | "engines": { 16 | "node": ">=0.11.12" 17 | }, 18 | "devDependencies": { 19 | "should": "^8.4.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /provided.al2/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided.al2 2 | 3 | FROM lambci/lambda-base-2:build 4 | 5 | COPY --from=0 /var/runtime /var/runtime 6 | COPY --from=0 /var/lang /var/lang 7 | COPY --from=0 /var/rapid /var/rapid 8 | 9 | # Add these as a separate layer as they get updated frequently 10 | RUN pipx install awscli==1.* && \ 11 | pipx install aws-lambda-builders==1.2.0 && \ 12 | pipx install aws-sam-cli==1.15.0 13 | -------------------------------------------------------------------------------- /provided.al2/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided 2 | 3 | 4 | FROM lambci/lambda-base-2 5 | 6 | ENV PATH=/var/lang/bin:$PATH \ 7 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH 8 | 9 | COPY --from=0 /var/runtime/init /var/runtime/init 10 | 11 | USER sbx_user1051 12 | 13 | ENTRYPOINT ["/var/runtime/init"] 14 | -------------------------------------------------------------------------------- /provided/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | COPY --from=0 /var/runtime /var/runtime 6 | COPY --from=0 /var/lang /var/lang 7 | COPY --from=0 /var/rapid /var/rapid 8 | 9 | # Add these as a separate layer as they get updated frequently 10 | # The pipx workaround is due to https://github.com/pipxproject/pipx/issues/218 11 | RUN source /usr/local/pipx/shared/bin/activate && \ 12 | pipx install awscli==1.* && \ 13 | pipx install aws-lambda-builders==1.2.0 && \ 14 | pipx install aws-sam-cli==1.15.0 15 | -------------------------------------------------------------------------------- /provided/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1 2 | WORKDIR /app 3 | COPY go.mod go.sum ./ 4 | RUN go mod download 5 | COPY init.go ./ 6 | RUN GOARCH=amd64 GOOS=linux go build init.go 7 | 8 | 9 | FROM lambci/lambda-base 10 | 11 | COPY --from=0 /app/init /var/runtime/init 12 | 13 | USER sbx_user1051 14 | 15 | ENTRYPOINT ["/var/runtime/init"] 16 | -------------------------------------------------------------------------------- /provided/run/go.mod: -------------------------------------------------------------------------------- 1 | module init 2 | 3 | require ( 4 | github.com/go-chi/chi v4.0.2+incompatible 5 | github.com/go-chi/render v1.0.1 6 | github.com/rjeczalik/notify v0.9.2 7 | ) 8 | 9 | go 1.15 10 | -------------------------------------------------------------------------------- /provided/run/go.sum: -------------------------------------------------------------------------------- 1 | github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs= 2 | github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= 3 | github.com/go-chi/render v1.0.1 h1:4/5tis2cKaNdnv9zFLfXzcquC9HbeZgCnxGnKrltBS8= 4 | github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns= 5 | github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8= 6 | github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM= 7 | golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7 h1:bit1t3mgdR35yN0cX0G8orgLtOuyL9Wqxa1mccLB0ig= 8 | golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 9 | -------------------------------------------------------------------------------- /python2.7/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:python2.7 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | ENV AWS_EXECUTION_ENV=AWS_Lambda_python2.7 6 | 7 | COPY --from=0 /var/runtime /var/runtime 8 | COPY --from=0 /var/lang /var/lang 9 | COPY --from=0 /var/rapid /var/rapid 10 | 11 | # Add these as a separate layer as they get updated frequently 12 | RUN curl --silent --show-error --retry 5 https://bootstrap.pypa.io/2.7/get-pip.py | python && \ 13 | pip install -U 'virtualenv>=16.0.0,<20.0.0' pipenv wheel --no-cache-dir && \ 14 | curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/1.1.4/get-poetry.py | POETRY_VERSION=1.1.4 python && \ 15 | pip install -U awscli boto3 aws-sam-cli==0.22.0 aws-lambda-builders==0.4.0 --no-cache-dir 16 | 17 | ENV PATH=/root/.poetry/bin:$PATH 18 | -------------------------------------------------------------------------------- /python2.7/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided 2 | 3 | 4 | FROM lambci/lambda-base 5 | 6 | ENV AWS_EXECUTION_ENV=AWS_Lambda_python2.7 7 | 8 | RUN rm -rf /var/runtime /var/lang && \ 9 | curl https://lambci.s3.amazonaws.com/fs/python2.7.tgz | tar -zx -C / 10 | 11 | RUN rm /var/runtime/awslambda/runtime.so 12 | COPY runtime_mock.py /var/runtime/awslambda/runtime.py 13 | 14 | COPY --from=0 /var/runtime/init /var/runtime/mockserver 15 | 16 | USER sbx_user1051 17 | 18 | ENTRYPOINT ["/usr/bin/python2.7", "/var/runtime/awslambda/bootstrap.py"] 19 | -------------------------------------------------------------------------------- /python3.6/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:python3.6 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_python3.6 \ 8 | PKG_CONFIG_PATH=/var/lang/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig \ 9 | PIPX_BIN_DIR=/var/lang/bin \ 10 | PIPX_HOME=/var/lang/pipx 11 | 12 | COPY --from=0 /var/runtime /var/runtime 13 | COPY --from=0 /var/lang /var/lang 14 | COPY --from=0 /var/rapid /var/rapid 15 | 16 | RUN export PYTHON_VERSION=3.6.12 && \ 17 | sed -i '/^prefix=/c\prefix=/var/lang' /var/lang/lib/pkgconfig/python-3.6.pc && \ 18 | curl https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz | tar -xJ && \ 19 | cd Python-${PYTHON_VERSION} && \ 20 | LIBS="$LIBS -lutil -lrt" ./configure --prefix=/var/lang && \ 21 | make -j$(getconf _NPROCESSORS_ONLN) libinstall libainstall inclinstall && \ 22 | cd .. && \ 23 | rm -rf Python-${PYTHON_VERSION} 24 | 25 | # Add these as a separate layer as they get updated frequently 26 | RUN pip install -U pip setuptools wheel --no-cache-dir && \ 27 | pip install pipx --no-cache-dir && \ 28 | pipx install virtualenv && \ 29 | pipx install pipenv && \ 30 | pipx install poetry==1.1.4 && \ 31 | pipx install awscli==1.* && \ 32 | pipx install aws-lambda-builders==1.2.0 && \ 33 | pipx install aws-sam-cli==1.15.0 34 | -------------------------------------------------------------------------------- /python3.6/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided 2 | 3 | 4 | FROM lambci/lambda-base 5 | 6 | ENV PATH=/var/lang/bin:$PATH \ 7 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 8 | AWS_EXECUTION_ENV=AWS_Lambda_python3.6 9 | 10 | RUN rm -rf /var/runtime /var/lang && \ 11 | curl https://lambci.s3.amazonaws.com/fs/python3.6.tgz | tar -zx -C / 12 | 13 | RUN rm /var/runtime/awslambda/runtime.cpython-36m-x86_64-linux-gnu.so 14 | COPY runtime_mock.py /var/runtime/awslambda/runtime.py 15 | 16 | COPY --from=0 /var/runtime/init /var/runtime/mockserver 17 | 18 | USER sbx_user1051 19 | 20 | ENTRYPOINT ["/var/lang/bin/python3.6", "/var/runtime/awslambda/bootstrap.py"] 21 | -------------------------------------------------------------------------------- /python3.7/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:python3.7 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_python3.7 \ 8 | PKG_CONFIG_PATH=/var/lang/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig \ 9 | PIPX_BIN_DIR=/var/lang/bin \ 10 | PIPX_HOME=/var/lang/pipx 11 | 12 | COPY --from=0 /var/runtime /var/runtime 13 | COPY --from=0 /var/lang /var/lang 14 | COPY --from=0 /var/rapid /var/rapid 15 | 16 | # Add these as a separate layer as they get updated frequently 17 | RUN pip install -U pip setuptools wheel --no-cache-dir && \ 18 | pip install pipx --no-cache-dir && \ 19 | pipx install virtualenv && \ 20 | pipx install pipenv && \ 21 | pipx install poetry==1.1.4 && \ 22 | pipx install awscli==1.* && \ 23 | pipx install aws-lambda-builders==1.2.0 && \ 24 | pipx install aws-sam-cli==1.15.0 25 | -------------------------------------------------------------------------------- /python3.7/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided 2 | 3 | 4 | FROM lambci/lambda-base 5 | 6 | ENV PATH=/var/lang/bin:$PATH \ 7 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 8 | AWS_EXECUTION_ENV=AWS_Lambda_python3.7 9 | 10 | RUN rm -rf /var/runtime /var/lang /var/rapid && \ 11 | curl https://lambci.s3.amazonaws.com/fs/python3.7.tgz | tar -zx -C / 12 | 13 | COPY --from=0 /var/runtime/init /var/rapid/init 14 | 15 | USER sbx_user1051 16 | 17 | ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap"] 18 | -------------------------------------------------------------------------------- /python3.8/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:python3.8 2 | 3 | FROM lambci/lambda-base-2:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_python3.8 \ 8 | PKG_CONFIG_PATH=/var/lang/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig \ 9 | PIPX_BIN_DIR=/var/lang/bin \ 10 | PIPX_HOME=/var/lang/pipx 11 | 12 | COPY --from=0 /var/runtime /var/runtime 13 | COPY --from=0 /var/lang /var/lang 14 | COPY --from=0 /var/rapid /var/rapid 15 | 16 | # Add these as a separate layer as they get updated frequently 17 | RUN pip install -U pip setuptools wheel --no-cache-dir && \ 18 | pip install pipx --no-cache-dir && \ 19 | pipx install virtualenv && \ 20 | pipx install pipenv && \ 21 | pipx install poetry==1.1.4 && \ 22 | pipx install awscli==1.* && \ 23 | pipx install aws-lambda-builders==1.2.0 && \ 24 | pipx install aws-sam-cli==1.15.0 25 | -------------------------------------------------------------------------------- /python3.8/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base 2 | 3 | RUN curl https://lambci.s3.amazonaws.com/fs/python3.8.tgz | tar -zx -C /opt 4 | 5 | 6 | FROM lambci/lambda:provided 7 | 8 | 9 | FROM lambci/lambda-base-2 10 | 11 | ENV PATH=/var/lang/bin:$PATH \ 12 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 13 | AWS_EXECUTION_ENV=AWS_Lambda_python3.8 14 | 15 | COPY --from=0 /opt/* /var/ 16 | 17 | COPY --from=1 /var/runtime/init /var/rapid/init 18 | 19 | USER sbx_user1051 20 | 21 | ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"] 22 | 23 | -------------------------------------------------------------------------------- /ruby2.5/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:ruby2.5 2 | 3 | FROM lambci/lambda-base:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_ruby2.5 \ 8 | GEM_HOME=/var/runtime \ 9 | GEM_PATH=/var/task/vendor/bundle/ruby/2.5.0:/opt/ruby/gems/2.5.0:/var/lang/lib/ruby/gems/2.5.0 \ 10 | RUBYLIB=/var/task:/var/runtime/lib:/opt/ruby/lib \ 11 | BUNDLE_SILENCE_ROOT_WARNING=1 12 | 13 | COPY --from=0 /var/runtime /var/runtime 14 | COPY --from=0 /var/lang /var/lang 15 | COPY --from=0 /var/rapid /var/rapid 16 | 17 | # Add these as a separate layer as they get updated frequently 18 | # The pipx workaround is due to https://github.com/pipxproject/pipx/issues/218 19 | RUN source /usr/local/pipx/shared/bin/activate && \ 20 | pipx install awscli==1.* && \ 21 | pipx install aws-lambda-builders==1.2.0 && \ 22 | pipx install aws-sam-cli==1.15.0 && \ 23 | gem update --system --no-document && \ 24 | gem install --no-document bundler -v '~> 2.1' 25 | -------------------------------------------------------------------------------- /ruby2.5/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:provided 2 | 3 | 4 | FROM lambci/lambda-base 5 | 6 | ENV PATH=/var/lang/bin:$PATH \ 7 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 8 | AWS_EXECUTION_ENV=AWS_Lambda_ruby2.5 9 | 10 | RUN rm -rf /var/runtime /var/lang /var/rapid && \ 11 | curl https://lambci.s3.amazonaws.com/fs/ruby2.5.tgz | tar -zx -C / 12 | 13 | COPY --from=0 /var/runtime/init /var/rapid/init 14 | 15 | USER sbx_user1051 16 | 17 | ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap"] 18 | -------------------------------------------------------------------------------- /ruby2.7/build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda:ruby2.7 2 | 3 | FROM lambci/lambda-base-2:build 4 | 5 | ENV PATH=/var/lang/bin:$PATH \ 6 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 7 | AWS_EXECUTION_ENV=AWS_Lambda_ruby2.7 \ 8 | GEM_HOME=/var/runtime \ 9 | GEM_PATH=/var/task/vendor/bundle/ruby/2.7.0:/opt/ruby/gems/2.7.0:/var/lang/lib/ruby/gems/2.7.0 \ 10 | RUBYLIB=/var/task:/var/runtime/lib:/opt/ruby/lib \ 11 | BUNDLE_SILENCE_ROOT_WARNING=1 12 | 13 | COPY --from=0 /var/runtime /var/runtime 14 | COPY --from=0 /var/lang /var/lang 15 | COPY --from=0 /var/rapid /var/rapid 16 | 17 | # Add these as a separate layer as they get updated frequently 18 | RUN pipx install awscli==1.* && \ 19 | pipx install aws-lambda-builders==1.2.0 && \ 20 | pipx install aws-sam-cli==1.15.0 && \ 21 | gem update --system --no-document && \ 22 | gem install --no-document bundler -v '~> 2.1' 23 | -------------------------------------------------------------------------------- /ruby2.7/run/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base 2 | 3 | RUN curl https://lambci.s3.amazonaws.com/fs/ruby2.7.tgz | tar -zx -C /opt 4 | 5 | 6 | FROM lambci/lambda:provided 7 | 8 | 9 | FROM lambci/lambda-base-2 10 | 11 | ENV PATH=/var/lang/bin:$PATH \ 12 | LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ 13 | AWS_EXECUTION_ENV=AWS_Lambda_ruby2.7 14 | 15 | COPY --from=0 /opt/* /var/ 16 | 17 | COPY --from=1 /var/runtime/init /var/rapid/init 18 | 19 | USER sbx_user1051 20 | 21 | ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"] 22 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var should = require('should') 2 | require('child_process').spawnSync = mockSpawnSync 3 | 4 | var dockerLambda = require('.') 5 | 6 | var captured = {} 7 | var mockReturn 8 | function mockSpawnSync(cmd, args, options) { 9 | captured.cmd = cmd 10 | captured.args = args 11 | captured.options = options 12 | return mockReturn 13 | } 14 | function resetMock(returnVal) { 15 | mockReturn = returnVal || {status: 0, stdout: '{}'} 16 | } 17 | 18 | // Should return defaults if calling with no options 19 | resetMock() 20 | var result = dockerLambda() 21 | captured.cmd.should.equal('docker') 22 | captured.args.should.eql([ 23 | 'run', 24 | '-v', 25 | __dirname + ':/var/task', 26 | '--rm', 27 | 'lambci/lambda:nodejs4.3', 28 | 'index.handler', 29 | '{}', 30 | ]) 31 | captured.options.should.eql({encoding: 'utf8'}) 32 | result.should.eql({}) 33 | 34 | // Should use env vars if asked to 35 | resetMock() 36 | result = dockerLambda({addEnvVars: true}) 37 | captured.cmd.should.equal('docker') 38 | captured.args.should.eql([ 39 | 'run', 40 | '-v', 41 | __dirname + ':/var/task', 42 | '--rm', 43 | '-e', 44 | 'AWS_REGION', 45 | '-e', 46 | 'AWS_DEFAULT_REGION', 47 | '-e', 48 | 'AWS_ACCOUNT_ID', 49 | '-e', 50 | 'AWS_ACCESS_KEY_ID', 51 | '-e', 52 | 'AWS_SECRET_ACCESS_KEY', 53 | '-e', 54 | 'AWS_SESSION_TOKEN', 55 | '-e', 56 | 'AWS_LAMBDA_FUNCTION_NAME', 57 | '-e', 58 | 'AWS_LAMBDA_FUNCTION_VERSION', 59 | '-e', 60 | 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE', 61 | '-e', 62 | 'AWS_LAMBDA_FUNCTION_TIMEOUT', 63 | '-e', 64 | 'AWS_LAMBDA_FUNCTION_HANDLER', 65 | '-e', 66 | 'AWS_LAMBDA_EVENT_BODY', 67 | '-e', 68 | 'DOCKER_LAMBDA_USE_STDIN', 69 | 'lambci/lambda:nodejs4.3', 70 | 'index.handler', 71 | '{}', 72 | ]) 73 | captured.options.should.eql({encoding: 'utf8'}) 74 | result.should.eql({}) 75 | 76 | // Should return spawn result if asked to 77 | resetMock({status: 0, stdout: 'null'}) 78 | result = dockerLambda({returnSpawnResult: true}) 79 | result.should.eql({status: 0, stdout: 'null'}) 80 | 81 | // Should not fail if stdout contains logging 82 | resetMock({status: 0, stdout: 'Test\nResult\n{"success":true}'}) 83 | result = dockerLambda() 84 | result.should.eql({success: true}) 85 | 86 | // Should not fail if stdout contains extra newlines 87 | resetMock({status: 0, stdout: 'Test\nResult\n\n{"success":true}\n\n'}) 88 | result = dockerLambda() 89 | result.should.eql({success: true}) 90 | 91 | // Should return undefined if last stdout entry cannot be parsed 92 | resetMock({status: 0, stdout: 'Test\nResult\nsuccess'}) 93 | result = dockerLambda() 94 | should.not.exist(result) 95 | 96 | // Should return undefined when function was successful but there is no stdout 97 | resetMock({status: 0, stdout: ''}) 98 | result = dockerLambda() 99 | should.not.exist(result) 100 | 101 | // Should throw error if spawn returns error 102 | resetMock({error: new Error('Something went wrong')}) 103 | var err 104 | try { 105 | result = dockerLambda() 106 | } catch (e) { 107 | err = e 108 | } 109 | err.should.eql(new Error('Something went wrong')) 110 | 111 | // Should throw error if spawn process dies 112 | resetMock({status: 1, stdout: 'wtf', stderr: 'ftw'}) 113 | try { 114 | result = dockerLambda() 115 | } catch (e) { 116 | err = e 117 | } 118 | var expectedErr = new Error('wtf') 119 | expectedErr.code = 1 120 | expectedErr.stdout = 'wtf' 121 | expectedErr.stderr = 'ftw' 122 | err.should.eql(expectedErr) 123 | 124 | console.log('All Passed!') 125 | --------------------------------------------------------------------------------