implementing Terraform and AWS Lambda Layer Deployment Using S3
I'm wondering if anyone has experience with I can't seem to get I just started working with This might be a silly question, but I'm having trouble deploying an AWS Lambda function that uses a Lambda Layer stored in an S3 bucket using Terraform. I've set up my Terraform configuration to create both the Lambda function and the S3 bucket for the layer, but I'm working with an behavior during the `terraform apply` phase. The behavior message I'm receiving is: ``` behavior: behavior creating Lambda Function: InvalidParameterValueException: Layer version not found. ``` I've tried specifying the layer version using the output of the S3 bucket, but it seems like the Lambda want to find the layer. Here's my relevant Terraform configuration: ```hcl resource "aws_s3_bucket" "lambda_layer_bucket" { bucket = "my-lambda-layer-bucket" acl = "private" } resource "aws_s3_bucket_object" "lambda_layer_zip" { bucket = aws_s3_bucket.lambda_layer_bucket.bucket key = "my_layer.zip" source = "./path/to/my_layer.zip" } resource "aws_lambda_layer_version" "my_lambda_layer" { layer_name = "my-layer" s3_bucket = aws_s3_bucket.lambda_layer_bucket.bucket s3_key = aws_s3_bucket_object.lambda_layer_zip.key compatible_runtimes = ["python3.8"] } resource "aws_lambda_function" "my_lambda_function" { function_name = "my_function" s3_bucket = aws_s3_bucket.lambda_layer_bucket.bucket s3_key = aws_s3_bucket_object.lambda_layer_zip.key runtime = "python3.8" handler = "handler.main" layers = [aws_lambda_layer_version.my_lambda_layer.arn] } ``` The layer is created successfully, but it seems that when I try to deploy the Lambda function, it want to find the layer version. I've also confirmed that the layer is uploaded to S3, and I can see it in the AWS console. I've ensured that all my IAM roles and permissions are correctly set up as well. I even tried to hardcode the ARN of the layer version in the `layers` attribute, but that didn't resolve the scenario. Could there be a timing scenario with the layer creation and Lambda function deployment? Should I be using `depends_on` to explicitly define the dependency? Any insight or best practices to resolve this would be greatly appreciated. This is part of a larger service I'm building. Is there a better approach? My development environment is Ubuntu. This issue appeared after updating to Hcl 3.11. I recently upgraded to Hcl stable. Is there a better approach? Thanks for taking the time to read this!