通过SAM启动时,是否有任何方法可以查看Shell脚本的输出

问题描述

我正在尝试构建多层Python SAM(AWS无服务器应用程序模型)应用程序。

没什么好看的,但是它有一些依赖关系,可以使用pipenv进行管理。

SAM有一个sam build命令,该命令在幕后使用make。 我有一个Makefile,看起来像这样:

# Empty build target for "sam build". Why?
# 1. "sam build Layers" works
# 2. "sam build" for the main function doesn't (it tries to use pip and crashes)
# With this empty target the main build is skipped and only the layers are built,which is enough.
build-Function: ;

build-Layers:
    bash pip-install.sh "$(ARTIFACTS_DIR)"

pip-install.sh看起来像这样:

#!/bin/bash
ARTIFACTS_DIR="${1}"

set -eu

# Detect Cygwin: https://stackoverflow.com/a/20691293/1320143
uname="$(uname -s)"
if [[ "${uname}" =~ "Cygwin" ]]
then
    # AWS SAM for Windows passes a Windows path Cygwin tools (make,etc.) don't understand.
    ARTIFACTS_DIR="$(cygpath -u "${ARTIFACTS_DIR}")"
fi

PROJECT_PATH="$(echo "${ARTIFACTS_DIR}" | sed 's@/.aws-sam.*@@')"
PIPFILE_PATH="$(echo "${ARTIFACTS_DIR}" | sed 's@/.aws-sam.*@/../Pipfile.lock@' | xargs readlink -f)"

mkdir -p "${ARTIFACTS_DIR}/python"
# We're using pipenv,which does not use requirements.txt.
# requirements.txt is used by SAM to automatically package and deploy layers (dependencies).
# To avoid dependency/version duplication,we extract the info from the pipenv info.

jq -r '.default | to_entries[] | .key + .value.version' "${PIPFILE_PATH}" > requirements.txt

# For debugging purposes.
ls -lha

python -m pip install -r "${PROJECT_PATH}/requirements.txt" -t "${ARTIFACTS_DIR}/python"

重要的一点是,该项目使用pipenv来管理依赖项,而不是pip,而SAM使用make作为构建工具,但是之后,它只有一个{{1 }} 延期。该脚本基本上创建了pip可以理解的依赖项列表,然后pip将所有依赖项下载到一个文件夹中,然后将其打包为一个较大的层。

主要问题是调试。

我已经看到出于某些(恕我直言)愚蠢的原因,pip隐藏了它启动的Shell脚本的输出make应该被欺骗来显示它,它是这样的:See output of shell script in Makefile

我已经尝试过了,但是没有用。我运行make,但只看到sam build Layers输出。我已经尝试过sam,同样的事情。

有没有办法显示输出?我希望能够在--debug / make上下文中调试脚本,因为我不明白我遇到的一些错误

解决方法

在 re:Invent 2020 上,AWS 宣布 Lambda 现在可以使用 Docker 镜像。

让自己免于烦恼,只需使用它们?