Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to Reference a S3 file in Terraform

I have a S3 file called python.zip already uploaded which Im trying to reference to add it in Lambda Layer.
I am using aws_s3_object data/resource in Terraform but it is erroring out no matter what I do.

** Error: Invalid data source

on main.tf line 12, in data "aws_S3_object" "layer_object":
12: data "aws_S3_object" "layer_object" {

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The provider provider.aws does not support data source "aws_S3_object". **

Below Terraform code that I am using.

terraform {
  backend s3 {
    key             = "InstanceCleanup.tfstate"
    dynamodb_table  = "terraform-state-locking"
  }
}

provider "aws" {
  region = "us-east-1"
}

data "aws_S3_object" "layer_object" {
  bucket = "agent-buildup-806471337920"
  key    = "python.zip"
 }

resource "aws_lambda_layer_version" "my_layer" {
  filename            = "python.zip"
  layer_name          = "Requests-2.31.0"
  description         = "Requests module for python 3.8 compatibilty"
  compatible_runtimes = ["python3.8"]
  s3_bucket           = data.aws_S3_object.layer_object.bucket
  s3_key              = data.aws_S3_object.layer_object.key
}

## Lambda Function ##
resource "aws_lambda_function" "Instance_Cleanup" {
  function_name = "Instance-Cleanup-function"
  handler       = "Instance-Cleanup.lambda_handler"
  runtime       = "python3.8"
  filename      = "Instance-Cleanup.zip"
  timeout       = 10
  role          = aws_iam_role.Lambda_role.arn

  layers = [aws_lambda_layer_version.my_layer.arn]
  
  source_code_hash = filebase64sha256("Instance-Cleanup.zip")

  environment {
    variables = {
      pool_ids        = join(",", var.pool_ids)
      instance_names  = join(",", var.instance_names)
    }
  }

}

Help me guys !!!!

>Solution :

The data source name is aws_s3_object, with a lower case s3, not aws_S3_object.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading