How can I name my Amazon EC2 EBS volumes using the AWS Console? By default the name field is empty, and I can see no option to edit this, unlike the actual EC2 instance.
The "name" field ist just a tag. To edit this, klick on your EBS volume, go to "Tags" in the lower panel and you will already find a tag "Name" there. Fill in your desired name as the value and it will also show up in the overview panel.
The "Name" that shows up in the AWS console is just a tag. This applies to AMIs, volumes, instances, etc..
You can change it from the command line using ec2-api-tools with following command:
ec2addtag <entity_id> --tag Name=<name>
You can install ec2-api-tools (Ubuntu) by calling:
sudo apt-get install ec2-api-tools
Related
I know I can access the tags via the metadata and cli tools, but is there anyway to access them whilst running cloud-init? Ideally I'd like to look for a tag called hostname and use it to set the machine host name.
Thanks
This command can be run from userdata (or any time, really) to access the instance ID from the metadata, and use it to pull the tag called "hostname". You could assign this to a variable, or use the output to directly set the hostname of the instance.
aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].Tags[?Key==`hostname`].Value' --instance-id `curl -s http://169.254.169.254/latest/meta-data/instance-id`
In more recent versions of cloud-init, metadata is available via jinja templates. EC2 also recently started exposing tags via the EC2 instance metadata store. Taken together, you can use this information to retrieve tags as part of your cloud-init.
Example:
cloud-init query -f "{{ds.meta_data.tags.instance}}"
As part of the user data:
## template: jinja
#cloud-config
final_message: |
My name is {{ds.meta_data.tags.instance.Name}}
Is it possible to create an AMI from an ISO?
I am implementing a build system which uses the base iso, modifies it, installs stuff and then outputs it in .ovf and AMI.
.ovf works. But for AMI, all I could figure out is it needs pre existing AMI. Is this correct?
Is there any way to use an iso and generate an AMI?
Thanks.
When you say from ISO that tells me you're looking to create a trusted base VM. You want to install from scratch locally first and import that to ec2 as a trusted private AMI. If you don't mind using veewee there's an awesome post using veewee instead of packer here: veewee It's all setup for CentOS. All you need to do is clone it and tweak it for your use case.
But since you're looking for packer like I was then what you need is the virtualbox-iso builder in packer and some aws-cli commands to upload and create an AMI out of the OVA. Packer doesn't have a post-processor for this unfortunately. Then you can use vagrant to reference the new AMI for ec2 based development and use the vagrant-aws plugin to create new ami's out of your trusted base ami.
Here are the steps to follow:
1.) Create an S3 bucket for image imports.
2.) Set up your AWS account. Create 'vmimport' IAM role and policy as well as X509 key and cert pair in case you don't have it. You'll need this to register a private AMI. You will also reference the bucket's name for the policy.
3.) Build a VM with VirtualBox using packer's virtualbox-iso builder and have it output an image in ova format.
4.) use aws-cli with your aws account to upload the OVA to the bucket you created. aws s3 cp command.
5.) Register the OVA as an ami. You will use the aws ec2 import-image command for this. (This part can take a long time 30 min - 1 hour).
You can track progress with: aws ec2 describe-import-image-tasks The AMI will appear in your Private AMI list when it's done.
Vagrant includes a useful little plugin called vagrant-ami which lets you create EC2 custom AMIs:
$ vagrant create-ami new_image --name my-ami --desc "My AMI"
Then you can replace the AMI ID in your Vagrantfile with your custom one.
Basically I want to create a "snapshot" of my current Ubuntu box, which has compiled binaries and various apt-get packages installed on it. I want to create a docker instance of this as a file that I can distribute to my AWS ec2 instances which will be stored on S3 bucket that will be mounted by the ec2.
Is it possible to achieve this, and how do you get started?
You won't be able to take a snapshot of a current box and use it as a docker container, but you can certainly create a container to use on your EC2 instances.
Create a Dockerfile that builds the system exactly as you want it.
Once you've created the perfect Dockerfile, export a container to a tarball
Upload the tarball to S3
On your EC2 instances, download the tarball and import it as a Docker container.
Are you planning to use something like s3fs to mount an S3 bucket? Otherwise you can just copy the tarball from your bucket either as a userdata boot script or during a chef/puppet/ansible provisioning step. Depends how you want to structure it.
Okay, so I've encountered an insanely frustrating problem while trying to reach an AWS S3 Bucket through AWS CLI via the command prompt in Windows 7. The AWS CLI is "unable to locate credentials" a.k.a. the config.txt file # C:\Users\USERNAME\.aws\config.txt.
I've tried pathing to it by creating the AWS_CONFIG_FILE environmental variable in ControlPanel>System>AdvancedSystemSettings>EnvironmentalVariables, but no dice. I've also tried all of the above on another Win7 machine. Again, no dice.
What could I be missing here. Are there any special permission that need to be set for AWS CLI to accest config.txt? Help, before I poke my own eyes out!
The contents of config.txt, in case you're interested, are:
[default]
aws_access_key_id = key id here
aws_secret_access_key = key here
region = us-east-1
There is a another way to configure aws credentials while using command line tool.
You can pass credentials using windows command instead of passing through file.
Execute below command from windows command prompt
aws configure
It prompt you to enter below things
AWS Access key ID:
AWS secrete key ID:
Default region Name:
Default output Format:
See this video tutorial: https://youtu.be/hhXj8lM_jBs
Okay, so the config file cannot be a text file (.txt). You should create the file in CMD, and it should be a generic file w/o any extension.
A couple of points on this as I had similar problems whilst trying to perform an S3 sync.
My findings were as follows.
Remove the spaces between hte = and the key value pair (see example below).
The OP has specified a [default] section in their example, but I got the same error when I had removed this section as I did not think it was needed so it's worth nothing this is needed.
I then reformed my file as follows and it worked...
[default]
aws_access_key_id=****
aws_secret_access_key=****
region=eu-west-2
[deployment-profile]
aws_access_key_id=****
aws_secret_access_key=****
region=eu-west-2
I had to include a blank line at the bottom of my credentials file.
Just posting this really as I struggled for a few hours with vague messages from AWS and these were the solutions that worked for me. Hope that it helps someone.
If like me you have a custom IAM user in your credentials file rather than 'default', try setting the AWS_DEFAULT_PROFILE env variable to the name of your IAM user, and then running commands.
[user1]
ACCESS_KEY=
SECRET_KEY=
set AWS_DEFAULT_PROFILE=user1
aws <command>
Alternatively you can specify the --profile variable each time you use the cli:
aws <command> --profile user1
I have some micro instances with EBS volumes and from the ec2 console you can right click and create a AMI image of the whole system.
But I bought some High-Memory Reserved Instances which had 500GB of storage so I installed a "Instance Store" ubuntu AMI image
Now I have configured everything on my server and want to create a instance store ami image so that I can install those images on new servers and I don't have to install everything again
How can I do this?
This is how you do it with Ubuntu:
Launch desired instance from here (pick one without EBS storage): http://cloud-images.ubuntu.com/releases/precise/release/
Follow this guide here (look below for hints concerning Ubuntu): http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/creating-snapshot-s3-linux.html
First you need to create you public key and certificate using this guide (you will need them later): http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-credentials.html#using-credentials-certificate
Also note your AWS Account ID:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-credentials.html#using-credentials-account-id
Upload your pk and cert to your ubuntu instance that you downloaded:
scp -i <path-to-your-ec2key>.pem <your-account-pk>.pem <your-account-cert>.pem ubuntu#<yourinstance>.<yourzone>.compute.amazonaws.com:~/
That puts the pk-file and cert-file in you home directory in your running instance. Now login and move these to the /mnt directory so that they do not get included when you bundle your AMI.
Now modify your image to your hearts content.
Install EC2 AMI Tools: sudo apt-get install ec2-ami-tools
Run the following command to create your bundle: ec2-bundle-vol -k <your-account-pk>.pem -c <your-account-cert>.pem -u <user_id>
Se guide above for the rest. You need to upload you bundle to S3 and then register your AMI so you can launch it.
Good Luck!