How to install an SSM agent in a EC2 instance running in Private Subnet (no NAT)

Hello,

I have an EC2 instance that runs out of an AMI (Ubuntu-based) built by our team. The AMI doesn’t have either “aws” cli or “ssm” agent preinstalled, and they will NOT do it as part of their build.

I need to launch this instance in a Private Subnet, where it has rules only to talk to VPC Endpoints. There is no NAT gateway or IGW attached to this VPC.

So I have uploaded the SSM binary (.deb) to S3 bucket, so the EC2 instance can pull that using S3 VPC Endpoint. But the catch is, I don’t have “aws” cli to run the aws s3 cp s3uri <localpath> --endpoint-url <url> command.

Do you have any ideas on how I can install an SSM agent on this EC2 instance?
PS: I have a total of 15 such AMIs, and I need to launch one instance for each AMI.

Thanks.

a temporary ebs volume?

You could add an s3 gateway to the subnet and then download the file from s3 via wget or curl?

Build a new AMI on top of theirs using Packer, run the build in a public subnet?

Alternatively, I guess you could make the deb file public and call the S3 api directly through http. Or generate a signed request yourself but that’s a bit more effort than at least I would consider worth it.

Can you launch an instance running Amazon Linux? This image already has the CLI and SSM agent pre-installed.

If you can, then you can use this as a jump station. Use this instance to copy the installer from S3 and scp that over to your Ubuntu instance. Do the same for the same agent.

Once you have the installers on the machine, you should be able to install the CLI and agent. Make sure you have the right permissions attached to the IAM role to ensure you can access the SSM service.

In addition, since you don’t have internet connectivity in your vpc, you will need an interface endpoint to the SSM service to actually use the service.

Why can’t you install the AWS cli on the AMI?

SCP unless you’re saying you can’t connect to the instance (ssh).

The AMI doesn’t have either “aws” cli or “ssm” agent preinstalled, and they will NOT do it as part of their build.

lol just make it a security requirement and refuse to deploy it without it.

For the use of ssm he will also need 3 more endpoints Sam Sam message and ec2 I believe

You can use the user-data of the EC2 instance to run a script when the instance is created. The script can install aws cli, ssm and do whatever you want to the instance.

u/MinionAgent that requires a connection to the Internet.

Thanks, everyone, for giving some ideas; what I noticed is when I converted the OVA to AMI using aws ec2 import-image, I saw AWS added the SSM agent during the AMI creation process. I was not expecting that.

Out of 11 AMIs, 10 are communicating via SSM, but one is not, and I am checking what is wrong with it. (At this time, I am trying to recreate the AMI for that one with the hope it will work).

It’s because the image is original purpose is not meant for launch the AWS EC2 instances.

I like this idea to try for sure, and I believe, theoretically, it should work.

Yes, I do have SSM endpoints, but for SSM to work, the SSM agent needs to be first installed and communicated.

Ohh I missed that part :stuck_out_tongue:

I think you need to fight for at least AWS CLI, technically you can pull the files from S3 without the client using your VPC endpoint, but you will have to manage the keys and it is probably worse solution than just installing the CLI.

Other option could be to have a EBS volume to attach with user-data and have the required tools there and detach it once your are done, but its more and more complex stuff just to avoid installing the CLI.

how it can be used?