amazon-web-services - AWS SAM 生成的构建规范从哪里获取 S3_BUCKET 值?

标签 amazon-web-services aws-cloudformation aws-sam aws-sam-cli esbuild

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 存储桶中。我希望这有帮助

/image/p7g4y.jpg

这是aws documentation as well

关于amazon-web-services - AWS SAM 生成的构建规范从哪里获取 S3_BUCKET 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75715752/

相关文章:

amazon-web-services - 使用 AWS Cloudformation 创建 SNS 平台应用程序?

amazon-web-services - elasticsearch cloudformation yaml 文件不起作用

java - 如何使用 Code Pipeline 持续部署到 CloudFormation 堆栈

aws-cloudformation - 由于未找到处理程序错误,无法部署 aws sam 堆栈

node.js - 在 EC2 中使用 S3 SDK 时出现 CredentialsError : Missing credentials in config.

amazon-web-services - 成本管理器中的 AWS 个性化

amazon-web-services - AWS Cloudfront 作为具有自定义域的 Heroku 站点的 CDN

amazon-ec2 - 当停止 ebs 支持的实例时,交换会消失。

python-3.x - 使用 Dynamorm 在 Python 中构建 AWS SAM 嵌套应用程序

amazon-web-services - 生产中的 AWS SAM 和 DynamoDB 表