简体   繁体   English

使用 Git 存储库作为 Terraform 中的 AWS Lambda 源的最佳方法?

[英]Best way to use Git repository as an AWS Lambda source within Terraform?

I'm working with Terraform to configure an AWS Lambda with API Gateway and DynamoDB, for the infrastructure i'm using a private repository and for the Lambda code source i'm using a different private repository.我正在与 Terraform 一起使用 API 网关和 DynamoDB 配置 AWS Lambda,对于我使用私有存储库的基础设施和 Lambda 代码源,我使用不同的私有存储库。

After a research i have already found a way to download a source code to use in Terraform using:经过研究,我已经找到了一种下载源代码以在 Terraform 中使用的方法:

locals {
  package_url = "https://github.com/.../main.zip"
  downloaded  = "downloaded_package_${md5(local.package_url)}.zip"
  lambda_src_path = "${path.module}/lambda"

 }

resource "null_resource" "download_package" {
     triggers = {
          downloaded = local.downloaded
     }

     provisioner "local-exec" {
         command = "curl -L -o ${local.downloaded} ${local.package_url}"
     }
 }

This would work fine if the repo is public, otherwise a solution would be using:如果回购是公开的,这会很好用,否则解决方案将使用:

curl -H 'Authorization: token TOKEN' \
-H 'Accept: application/vnd.github.v3.raw' \
-O \
-L https://api.github.com/repos/owner/repo/contents/path

I would like to ask what would be the best solution to achieve that, maybe using.env data inside the Terraform repository.我想问一下实现该目标的最佳解决方案是什么,也许是使用 Terraform 存储库中的 .env 数据。

Thanks谢谢

Don't store secrets in.env file, since those would be part of repo and at risk to be compromised.不要将秘密存储在 .env 文件中,因为它们将成为回购协议的一部分并且有被泄露的风险。 You should never store secrets in repo.你永远不应该在回购中存储秘密。 The solution depends on where you actually have your repo hosted.解决方案取决于您实际托管存储库的位置。 But all providers support storing secrets one way or another.但是所有提供者都支持以一种或另一种方式存储秘密。

For example github has https://docs.github.com/en/actions/security-guides/encrypted-secrets例如 github 有https://docs.github.com/en/actions/security-guides/encrypted-secrets

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS Lambda 未使用 Terraform source_code_hash 属性进行更新 - AWS Lambda not updating using Terraform source_code_hash property Terraform:AWS Lambda 图像未更新 - Terraform: AWS Lambda with Image not updating 在 AWS Lambda 中加载 static 文件的最佳方式 - Best way to load static files inside AWS Lambda 为 AWS lambda 存储 Firebase 管理员私钥文件的最佳方式 - Best way to store Firebase admin private key file for AWS lambda 在 Python 中将 Elastic Beanstalk 与 AWS Lambda 集成的最佳方法 - best way to integrate Elastic Beanstalk with AWS Lambda in Python terraform 未检测到 lambda 源文件的更改 - terraform does not detect changes to lambda source files 在为 Google Source Repository 调用 git clone over HTTPS 时,有没有办法传递访问令牌 - Is there a way to pass access tokens when calling git clone over HTTPS for Google Source Repository 在 AWS CodeBuild 中运行 Terraform - 部署 lambda - Running Terraform in AWS CodeBuild - deploying lambda 有没有办法将 CORS 规则添加到 Terraform aws_s3_bucket 数据源? - Is there a way to add CORS rule to Terraform aws_s3_bucket data source? GiT 管道调用 lambda function 使用 terraform 创建, - GiT pipeline to invoke lambda function created using terraform,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM