Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
AWS Lambda doesn't wait for code to be uploaded to S3 bucket in Terraform script

I have following AWS Terraform config:

# S3 bucket for Lambda code upload
resource "aws_s3_bucket" "ada-upload" {
    bucket = "ada-upload"
    acl    = "private"
}

# uploading zipped lambda code to S3
resource "aws_s3_bucket_object" "lambda_code_upload" {
  bucket = aws_s3_bucket.ada-upload.bucket
  key    = "dist.zip"
  source = "dist.zip" 
  etag = filemd5("dist.zip")
}

# creating lambda function
resource "aws_lambda_function" "ada-lambda-function" {
  function_name = "ada-lambda-function"
  s3_bucket   = aws_s3_bucket.ada-upload.bucket
  s3_key      = "dist.zip" 
  memory_size = 1024
  timeout     = 900
  runtime          = "provided"
  source_code_hash = base64sha256("dist.zip")
}

Basically it creates an S3 bucket, uploads code there and then creates a Lambda from that code. Code is self-contained .NET 3.1 app, it brings its own runtime, so the Zip is quite large, it takes some time to upload. Lambda will wait for S3 bucket creation, but will not wait for code to finish uploading. So when I run the script initially I will get S3 key "dist.zip" doesn't exist error. When I rerun the script - since the zip is already there - function created successfully.

Is there a way to ensure Lambda to start creating only when code finishes uploading?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Disclaimer: @ydaetskcoR answer is correct and you should accept it. However, another approach would be to modify the lambda function as follows:

resource "aws_lambda_function" "ada-lambda-function" {
  function_name = "ada-lambda-function"
  s3_bucket   = aws_s3_bucket.ada-upload.bucket
  s3_key      = "dist.zip" 
  memory_size = 1024
  timeout     = 900
  runtime          = "provided"
  source_code_hash = base64sha256("dist.zip")

 depends_on = [
    aws_s3_bucket_object.lambda_code_upload,
  ]
}

This will force terraform to first wait for the object to be uploaded into the bucket before launching the lambda.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda