AWS SAM 新手。我使用 sam init
CLI 命令来配置一个新的准系统 Node 16.x/JavaScript lambda(无服务器应用程序),并且在很大程度上我了解所有自动生成的代码的作用,除了生成的buildspec.yml
:
version: 0.2
phases:
install:
commands:
# Install all dependencies (including dependencies for running tests)
- npm install
pre_build:
commands:
# Discover and run unit tests in the '__tests__' directory
- npm run test
# Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda
- rm -rf ./__tests__
# Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json)
- npm prune --production
build:
commands:
# Use AWS SAM to package the application by using AWS CloudFormation
- aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --output-template template-export.yml
artifacts:
type: zip
files:
- template-export.yml
看起来这个文件在我运行 sam build
时被执行,并且它看起来就像将我的代码打包到可部署的 Node/JavaScript 应用程序中(这将是作为 AWS JavaScript Lambda 可执行文件),看起来像是将此打包/可部署的应用程序发布到 S3 存储桶。我猜测当我运行sam部署
时,部署会指示CloudFormation将打包/可部署函数(存储在该S3位置)部署到我配置的Lambda作为其可执行代码。
因此,首先,如果我上面所说的任何内容不正确或错误,请首先纠正我并提供必要的类(class)更正!但假设我或多或少步入正轨......
我不明白 $S3_BUCKET
变量是如何或在哪里传入的。即使在执行了 grep
之后,我在生成的代码中的其他任何地方都看不到这一点>。我认为,由于这是标准的样板 AWS SAM,大多数其他项目都是使用相同类型的设置自动生成的,因此希望社区可以帮助我弄清楚:buildspec.yml 在哪里> (ESBuild?)找到 $S3_BUCKET
的值?
最佳答案
我经常使用 AWS SAM,虽然我不知道应用程序的每一个进出情况,但在打包应用程序时会传入 $S3_BUCKET 变量。这是我的应用程序的 makefile 作为示例。然后,cloudformation 的输出会被放到 AWS 的 s3 存储桶中。我希望这有帮助
关于amazon-web-services - AWS SAM 生成的构建规范从哪里获取 S3_BUCKET 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75715752/