简体   繁体   中英

Running Terraform in AWS CodeBuild - deploying lambda

I am trying to deploy a lambda function using Terraform running in AWS CodeBuild. I am able to deploy the lambda zip file from an S3 bucket but not when my buildspec file does the build first because I am doing Terraform apply in the POST BUILD phase - before the zip gets uploaded to S3. Is there a way to do the build and then deploy the zip using Terraform?

You shouldn't need to upload the zip to s3 first, add the zip location as the filename in terraform. I usually copy all assets into a folder called.assets as part of the build process then add it as the filename in the terraform. Like the below

resource "aws_lambda_function" "lambda_function" {
  ....
  filename                       = ".assets/my-module/lambda.zip"
  source_code_hash               = filebase64sha256(".assets/my-module/lambda.zip")
  ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM