Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!