How to upload files to S3 bucket using mime type

Viewed 20

I trying to figure out using AWS CLI how to upload only certain files to S3 bucket based on the mime type.

Currently I am using terraform script to do that.

locals { 
  mime_types = jsondecode(file("${path.module}/mime.json"))
}

resource "aws_s3_object" "frontend_bucket_objects" {
  for_each = fileset("${var.build_folder}", "**")
  bucket = "frontend-bucket"
  key = each.value
  source = "${var.build_folder}\\${each.value}"
  content_type = lookup(local.mime_types, regex("\\.[^.]+$", "${each.value}"), null)
  etag = filemd5("${var.build_folder}\\${each.value}")
}

mime.json

{
    ".aac": "audio/aac",
    ".abw": "application/x-abiword",
    ".arc": "application/x-freearc",
    ".avif": "image/avif",
    ".avi": "video/x-msvideo",
    ".azw": "application/vnd.amazon.ebook",
    ".bin": "application/octet-stream",
    ".bmp": "image/bmp",
    ".css": "text/css",
    ".csv": "text/csv",
    ".doc": "application/msword",
     ..
     .. etc etc
}

I want to upload using aws-cli but not able to figure out how to include files based on mime.

This is what I have right now which uploads entire source folder.

`aws s3 cp build/ s3://frontend-bucket --recursive`
0 Answers
Related