How to mount host storage /dev/xvda1 from AWS batch

0

I am using the AWS batch to launch several jobs at a time. I have created a snapshot of a 30G volume and added that to a launch template. I am using this launch template to create a "compute environment". I have also created a corresponding job definition by keeping "volume" and "mount point" empty. Now once a job is launched I would like to mount an attached EBS volume /dev/xvda1 to a local directory (say /storage) inside a container. How do I achieve this? I tried doing the following from inside a container by executing a simple python code:
$ mkdir /storage
$ sudo mount /dev/xvda1 /storage
This command creates /storage directory BUT DOES NOT mount it and throws an error "sudo not found". Without sudo it throws an error "permission denied".

How do I mount this volume from inside a container?
And if volume and mount point options of container properties are helpful then how do I set them if my host volume is /dev/xvda1 and mount directory is /storage?

NOTE: I do not prefer to use AWS CLI for this. I prefer using either boto3 or using python to run shell commands.

joshivm
asked 3 years ago846 views
1 Answer
0

I figured out the answer to this question. Keeping this thread alive just in case someone finds this helpful in the future.

  1. I launched an ECS-optimized AMI instance by attaching the EBS volume to it from the snapshot.
  2. Then I created a directory to mount the volume to.
  3. Then I edited /etc/fstab to automount the volume to the desired directory on boot.
  4. Then I shutdown the ecs process.
  5. Then I created a custom AMI from this instance.
  6. I use this custom AMI and specify this in the compute environment.
  7. Then in the job-definition, I set volume and mount point fields as follows:
    volume -> name = storage_name, source path = /storage
    mount_point -> container_path = /desired_path, source_path=storage_name (same as given in the volume field)

This makes it ready to have a larger volume ready with the job.

joshivm
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions