I am using aws cli command to get the instance IDs attached to a load balancer.
I have tried using aws cli command "aws elbv2" but this does not list EC2 instances like "aws elb" command
For classic load balancers you can use:
aws elb describe-load-balancers
And the output will include the Instance ID information
However, for application load balancers you have to use this command but the output does not include the instance IDs
aws elbv2 describe-load-balancers
How can i get the instance ID info with the aws elbv2 command? Or is there another command i can use to get the instances attached to the load balancer?
I want to copy an EBS snapshot to my S3 bucket, but i cannot find a way to do it after trying and researching.
I shall be grateful to you for any information that could get me started on a solution.
There is an answer within the AWS forums, but it's rather roundabout:
Create a temporary EBS volume from the snapshot. (Snapshots: Actions: Create volume)
Create a temporary EC2 Linux instance, install aws cli
Attach the volume to the instance and mount. (EBS Volumes: Actions: Attach volume - must be same availability zone)
find name of mounted snapshot volume from lsblk - eg /dev/xvdj
Copy the volume contents to your system - eg sudo bash -c "dd if=/dev/xvdj bs=8M | gzip > /home/ubuntu/volbk.gz"
Copy your .gz file to S3 - aws s3 cp ~/volbk.gz s3://my-bucket-name
check your s3 bucket contents arrived ok; unmount the snapshot volume
Terminate the instance.
Delete the snapshot EBS volume.
from here, with my additions (Nov 2 answer):
https://forums.aws.amazon.com/thread.jspa?messageID=151285
copy-snapshot command is the AWS CLI command that copies the snapshot of EBS volume and stores it in Amazon S3. You can copy the snapshot within the same region or from one region to another.
This example command copies the snapshot of arbitrary id from one region to another.
aws --region us-east-1 ec2 copy-snapshot --source-region us-west-2 --source-snapshot-id snap-066877671789bd71b --description "This is my copied snapshot."
for more info about this refer https://docs.aws.amazon.com/cli/latest/reference/ec2/copy-snapshot.html
With Amazon EBS, you can create point-in-time snapshots of volumes, which can be stored in Amazon S3. After you've created a snapshot and it has finished copying to Amazon S3, you can copy it from one AWS region to another, or within the same region. The snapshot copy ID is different than the ID of the original snapshot.
EBS snapshots are stored in Amazon S3. However, you will not find your snapshots in any of your S3 buckets. AWS uses the S3 infrastructure to store your EBS snapshots, but you cannot access them while they reside in S3.
You can copy the AWS EBS Snapshot using either AWS EC2 Console or Command Line.
i) Copy EBS snapshot using Console-:
Open the EC2 console-> Choose snapshot in the navigation pane-> Choose copy from actions list -> In Copy Snapshot dialog box provide necessary details like destination region, description, encryption etc and select copy.
ii) Copy EBS snapshot using Command line-:
Run the below command in AWS CLI:
aws --region <destination region> ec2 copy-snapshot --source -<source region> --source -snapshot-id <snap-0xyz9999999> --description
I want to configure an EC2 instance so that it installs, configures and starts an Apache web server without my (human) intervention.
To this end, I am taking advantage of the "User Data" section and I have written the following script:
#!/bin/bash
sudo apt-get upgrade
sudo apt-get install -y apache2
sudo apt-get install -y awscli
while [ ! -e /tmp/index.html ]; do aws s3 cp s3://vietnhi-s-bucket/index.html /var/www/html; done
sudo systemctl restart apache2
Description of the Functionality of the Bootup script:
The script forces an update of the Ubuntu instance from whatever the date of the AMI image was when the image was created to today, when the EC2 instance is created from the image.
The script installs the Apache 2 server.
The script installs the AWS CLI interface. Because the aws s3 cp command on the next line is not going to work without the AWS CLI interface.
The script copies the sample index.html file from the vietnhi-s-bucket S3 bucket to the /var/www/html directory of the Apache web server and overwrites its default index.html file.
The script restarts the Apache web server. I could have used "Start" but I chose to use "restart".
Explanatory Notes:
The script assumes that I have created an IAM role that permits AWS to copy the file index.html from an S3 bucket called "vietnhi-s-bucket". I have given the name "S3" to the IAM role and assigned the "S3ReadAccess" policy to that role.
The script assumes that I have created an S3 bucket called "vietnhi-s-bucket" where I have stashed a sample index.html file.
For reference, here are the contents of the sample index.html file:
[html]
[body]
This is a test
[/body]
[/html]
Does the bootup script work as intended?
The script works as-is.
To arrive at that script, I had to overcome three challenges:
Create an appropriate IAM role. The minimum viable role MUST include the "S3ReadAccess" policy. This role is absolutely necessary for AWS to be able to use the public and private access keys for your AWS account and that are loaded in your environment. Copying the index.html file from the Vietnhi-s-bucket S3 bucket is not feasible if AWS does not have access to your AWS account keys.
Install the AWS CLI interface (awscli). For whatever reason, I never saw that line included in any of the AWS official documentation or any of the support offered on the web including the AWS forums. You can't run the AWS CLI s3 cp command if you don't install the AWS CLI interface.
I originally used "aws s3 cp s3://vietnhi-s-bucket/index.html /var/www/html" as my original copy-from-S3 instruction. Bad call. https://forums.aws.amazon.com/thread.jspa?threadID=220187
The link above refers to a timing issue that AWS hasn't resolved and the only workaround is to wrap retries around the aws s3 cp command.
I've been using Apache Whirr(0.8.0) to create Hadoop+HBase clusters on EC2 using the CDH ami, turns out that Whirr is not using my whirr.location-id parameter. I specifically pass it as an argument --location-id=us-west-2 when I create the cluster and I also added it to the whirr recipe as whirr.location-id=us-west-2 but when I fire up the clusters they always get created in the us-east-1 region. My guess is that the Whirr recipe for CDH is overriding the region and I wonder if there is any way to disable this or force an specific EC2 region?
Any easy way to move and custom AMI image between regions? (tokyo -> singapore)
I know you can mess up with API and S3 to get it done, but there there any easier way to do it?
As of December, 2012, Amazon now supports migrating an AMI to another region through the UI tool (Amazon Management Console). See their documentation here
So, how I've done it is..
From the AMI find out the Snapshot-ID and how it is attached (e.g. /dev/sda1)
Select the Snapshot, click "Copy", set Destination region and make the copy (takes a while!)
Select the new Snapshot, click "Create Image"
Architecture: (choose 32 or 64 bit)
Name/Description: (give it one)
Kernel ID: when migrating a Linux AMI, if you choose "default" it may fail. What worked for me was to go to the Amazon Kernels listing here to find the kernels Amazon supports, then specify it when creating the image)
Root Device Name: /dev/sda1
Click "Yes, Create"
4.Launch an instance from the new AMI and test that you can connect.
You can do it using Eric's post:
http://alestic.com/2010/10/ec2-ami-copy
The following assumes your AWS Console utilities are installed in /opt/aws/bin/, JAVA_HOME=/usr and you are running i386 architecture, otherwise replace with x86_64.
1) Run a live snapshot, where you believe your image can fit in 1.5GB and you have that to spare in /mnt (check running df)
/opt/aws/bin/ec2-bundle-vol -d /mnt -k /home/ec2-user/.ec2/pk-XXX.pem -c /home/ec2-user/.ec2/cert-XXX.pem -u 123456789 -r i386 -s 1500
2) Upload to current region's S3 bucket
/opt/aws/bin/ec2-upload-bundle -b S3_BUCKET -m /mnt/image.manifest.xml -a abcxyz -s SUPERSECRET
3) Transfer the image to EU S3 bucket
/opt/aws/bin/ec2-migrate-image -K /home/ec2-user/.ec2/pk-XXX.pem -C /home/ec2-user/.ec2/cert-XXX.pem -o abcxyz -w SUPERSECRET --bucket S3_BUCKET_US --destination-bucket S3_BUCKET_EU --manifest image.manifest.xml --location EU
4) Register your AMI so you can fire up the instance in Ireland
/opt/aws/bin/ec2-register –K /home/ec2-user/.ec2/pk-XXX.pem –C /home/ec2-user/.ec2/cert-XXX.pem http://s3.amazonaws.com:80/S3_BUCKET/image.manifest.xml --region eu-west-1 -name DEVICENAME -a i386 --kernel aki-xxx
There are API tools for this. http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-MigrateImage.html
I think that is now outdated by ec2-bundle-vol and ec2-migrate-image, BTW you can also take a look at this Perl script by Lincoln D. Stein:
http://search.cpan.org/~lds/VM-EC2/bin/migrate-ebs-image.pl
Usage:
$ migrate-ebs-image.pl --from us-east-1 --to ap-southeast-1 ami-123456
Amazon have just announced support for this functionality in this blog post. Note that the answer from dmohr relates to copying EBSs, not AMIs.
In case the blog post is unavailable, quoting the relevant parts:
To use AMI Copy, simply select the AMI to be copied from within the
AWS Management Console, choose the destination region, and start the
copy. AMI Copy can also be accessed via the EC2 Command Line
Interface or EC2 API as described in the EC2 User’s Guide. Once the
copy is complete, the new AMI can be used to launch new EC2 instances
in the destination region.
AWS now supports the copy of an EBS snapshot to another region via UI/CLI/API. You can copy the snapshot and then make an AMI from it. Direct AMI copy is coming - from AWS:
"We also plan to launch Amazon Machine Image (AMI) Copy as a follow-up
to this feature, which will enable you to copy both public and
custom-created AMIs across regions.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-copy-snapshot.html?ref_=pe_2170_27415460
Ylastic allows you to move EBS backed linux images between regions.
Its $25 or $50 per month but it looks like you can evaluate it for a week.
I just did this using a script on CloudyScripts, worked fantastically: https://cloudyscripts.com/tool/show/5 (and it's free).
As of 2017, it's pretty simple.. just follow the screenshots:
I'll add Scalr to the list of tools you can use (Disclaimer: I work there). Within Scalr, you can create your own AMI (we call them roles). Once your role is ready, you just have to choose where you want to deploy it (so in any regions).
Scalr is open-source released under the Apache 2 license: you can to download it and install it yourself. Otherwise, it is also available through a hosted version including support. Alternatives to Scalr includes RightScale and enStratus.