kharandziuk
kharandziuk

Reputation: 12880

Terraform: how to access S3 bucket object from EC2 instance?

I have an archive that contains some binary on S3 which I need to put on EC2 during the provisioning. On the moment, I am downloading the archive to the machine(host provisioned) and upload it to the machine which I need to provision.

Or how can I get a link from aws_s3_bucket_object? or is there a way to mount s3 object as file into ec2 instance with terraform?

data "aws_s3_bucket_object" "release" {
  bucket = data.aws_s3_bucket.artifacts.id
  key    = "release.tgz"
}

resource "aws_instance" "engine" {
  ami           = data.aws_ami.server.id
  instance_type = var.aws_instance_type
  ...
}

Upvotes: 3

Views: 2428

Answers (1)

Marcin
Marcin

Reputation: 238081

Sadly, you can't mount S3 objects as a filesystem to your instance, nor access them directly. They have to be downloaded first.

However, you can use third part tool which make S3 bucket appear to you and your application as a filesystem. One popular tool for that is 3fs-fuse which :

allows Linux and macOS to mount an S3 bucket via FUSE. s3fs preserves the native object format for files, allowing use of other tools like AWS CLI.

For that to work you would have to setup your user_data in your instance to do it automatically during the instance launch.

Upvotes: 4

Related Questions