Apache brooklyn create own volumes instead of using the existing one - amazon-web-services

I use Apache Brooklyn 0.8.0-incubating to create d2.xlarge instance on AWS with the following Blueprint:
location:
jclouds:aws-ec2:
region: eu-central-1
...
provisioning.properties:
imageId: eu-central-1/ami-7bcddf17 # Redhat 6.6
hardwareId: d2.xlarge # with 2TB EBS
On the machine are only 10GB total storage. After some research I found the instance volume under /dev/xvdb unpartioned.
Can me anybody explain how I can use instance storage instead of creating a new volume for the machine on AWS?
Best Regards,
Felix

This is the expected behaviour for VMs in AWS EC2.
As described in http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/add-instance-store-volumes.html:
"After you launch the instance, you must ensure that the instance
store volumes for your instance are formatted and mounted before you can use them. Note that the root
volume of an instance store-backed instance is mounted automatically."
"the instance type determines which instance store volumes are mounted for you and which are available for you to mount yourself"
For your instance type, it looks like the instance store volume is attached unformatted.
The EC2 docs talk about running lsblk, mkfs and mount to format and mount the instance store volume.
Expected behaviour also depends on the AMI: "Each AMI has a block device mapping that specifies the block devices to attach to an instance when it is launched from the AMI. An AMI that Amazon provides includes a root device only."
Note that what you get working on one AMI might not work on all other AMIs (e.g. because of different block device mappings). Sticking with Amazon's own AMIs is often a good idea, for getting sensible default behaviour.
This could be automated in Apache Brooklyn. You have a few options for that:
Implement it in the entity, e.g. if using a SoftwareProcess entity then you could use the config key pre.install.command to execute the bash commands to set up the volume.
Implement it in the location.
This could use a new MachineLocationCustomizer to execute the commands on the machine (and then configure that on the location).
Alternatively, for jclouds locations you could use the setup.script configuration, which takes the URL of a shell script to execute.
Of those approaches, the MachineLocationCustomizer gives you the most power and flexibility.

Related

AWS launch new instance using Ubuntu 22.04: image has more volumes than instances allows

AWS launch new instance using Ubuntu 22.04:
The selected AMI contains more instance store volumes
than the instance allows. Only the first 0 instance
store volumes from the AMI will be accessible from the
instance
What does it mean? does an AMI have volumes?
EC2 instances can have two basic types of volumes: EBS (Elastic Block Store) and Instance Store. This article spells out the differences, but in a nutshell, EBS volumes are network attached storage that are independent of an instance, while Instance Store volumes are local block storage volumes that are not persistent (e.g. when the instance is terminated, the instance store volume is lost).
You ask if an AMI has volumes. An AMI basically is one or more volumes. The AMI is a snapshot of a disk in a particular state. These days, most modern AMIs use EBS storage for the root volume; that is, the volume that contains the operating system kernel that an instance boots from. It used to be commonplace to use Instance Store for the root volume, but EBS has become nearly as fast, more secure, and more reliable than Instance Store, so the use cases for Instance Store volumes are dwindling.
With all that said, I'm quite surprised that you're seeing this error. The error message suggests that the AMI includes Instance Store but the instance type you selected does not support Instance Store (many instance types do not). However, all Ubuntu 22.04 AMIs use EBS, not Instance Store. If you use the Ubuntu Amazon EC2 AMI Locator and search for "22.04", you'll find that all of the results have hvm:ebs-ssd as the instance type. Only very old Ubuntu AMIs have Instance Store volumes.
Make sure you are using the AMI Locator to find the Ubuntu 22.04 AMI. Those AMIs should work with most or all EC2 instance types.

Installed SW on EBS or Instance Store?

I have launched an ec2 RHEL instance and have attached EBS volume to it.
How do I know when I access data from /tmp or /opt or any other directory, whether the data is accessed from Instance Store or EBS?
The t2.medium instance type (mentioned in comments) does not include instance store volumes. You can review all instance types with instance store volumes here. In addition when launching instances with instance store volumes these aren't your root volume and are just available storage you can mount as an additional disk on the instance. For example if you launch a M5d.large instance, by default your instance store NVMe drive is available at /dev/nvme1n1 in linux, but is not used at launch time. You can format and use the instance store volume as you please, after launch.

Swap space using instance-store in HVM EBS AMI in AWS

On AWS EC2, if we launch and AMI with instance-store, we can attach EBS volume for persisent store. Is the vice-versa possible.
ie.,
Can we add instance-store volume when launching a EBS HVM AMI, the reason behind this is to use it as a swap.
I can't see the option to add Instance store on Storage Configuration, while launching a EBS backed instance.
Please let me know, if there is a method to achieve root volume as EBS and swap volume as instance-store.
many thanks,
Shan
If you are launching an instance class that includes instance store (ephemeral) disks, those should be accessible from Storage Configuration, as in this example, where the instance class provides two ephemeral disks.
See Instance Storage in the EC2 documentation to confirm whether the instance class you're launching includes instance store volumes. Some classes do not, and where that is the case, you can only select EBS as the Volume Type.
If you're launching from an AMI that already contains references to the ephemeral disks, you should see something like this screen shot. If it doesn't include references to the instance store volumes, you can use Add New Volume to include the desired instance store volumes with the new instance. Their sizes are fixed by the specs of the instance class, which is why Size says N/A. Since they are provided at no charge, you should always attach them at launch, even if you have no plan for them, because they can't be added after launching.
AMIs can't be edited, so if you want these included automatically on future launches, you'll need to build a new AMI, which you'll probably also want to be configured (within the OS boot sequence) to create and mount the desired swap space.

Backing up root device (mounted at /) of an AWS t2.micro instance running Ubuntu

I want to back up the root device (mounted at /) of my t2.micro instance running Ubuntu. I think the instance is EBS-backed as it is a t2 instance. So I was going to take snapshots of my root device to back it up.
However, it is recommended that I detach the root device before I back it up. There are two problems with this:
I have to use umount to unmount it first, which may cause my instance to crash. What is a safe way to handle this?
I want to run these backups as a cron job on the instance itself, but if my instance's root device is unmounted, will the cron job even run?
A more general question is: what is the best way to do this?
A possible solution might be: use AWS Lambda and execute a Lambda function based on a schedule executing the following commands by the use of the AWS SDK:
Stop EC2 instance
Create EBS snapshot
Start EC2 instance
First, I would confirm that your root device is in fact EBS backed.
Here are the basic steps to confirm:
To determine the root device type of an instance using the console
Open the Amazon EC2 console.
In the navigation pane, click Instances, and select the instance.
Check the value of Root device type in the Description tab as follows:
If the value is ebs, this is an Amazon EBS-backed instance.
If the value is instance store, this is an instance store-backed instance.
(Source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/RootDeviceStorage.html#display-instance-root-device-type)
AWS states as a best practice is to use snapshots or a backup tool.
Regularly back up your instance using Amazon EBS snapshots or a backup
tool.
(Source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-best-practices.html)
AWS states in the documentation that root EBS volumes should be shutdown before taking a snapshot.
To create a snapshot for Amazon EBS volumes that serve as root
devices, you should stop the instance before taking the snapshot.
(Source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-creating-snapshot.html)
So depending on your RPO (Recovery Point Objective), as a general rule it is a good practice to separate your data from your root volume. Store data that you need to keep on a separate EBS volume and take snapshots on the second EBS volume. This way you never have to worry about the instance itself - if it bonks out just launch a new instance and attach your snapshot.
If you have a special case that prevents you from using EBS snapshots, try using a role for your instance(s) that have permissions to read/write data to S3 buckets using your cron job.

How to load ESB Volume by ID via .ebextensions

I'm trying to mount the same volume for a Beanstalk build but can't figure out how to make it work with the volume-id.
I can attach a new volume, and I can attach one based on a snapshot ID but neither are what I'm after.
My current .ebextension
commands:
01umount:
command: "umount /dev/sdh"
ignoreErrors: true
02mkfs:
command: "mkfs -t ext3 /dev/sdh"
03mkdir:
command: "mkdir -p /media/volume1"
ignoreErrors: true
04mount:
command: "mount /dev/sdh /media/volume1"
option_settings:
- namespace: aws:autoscaling:launchconfiguration
option_name: BlockDeviceMappings
value: /dev/sdh=:20
Which of course will mount a new volume, not attach an existing one. Perhaps snapshot is what I want and I just don't understand the terminology here?
I need the same data that was on the volume when the autoscaling kicks in to be on each EC2 instants that scales... A snapshot would surely just be the data that existed at the point the snapshot was created?
Any ideas or better approaches?
Elastic Block Store (EBS) allows you to create, snapshot/clone, and destroy virtual hard drives for EC2 instances. These drives ("volumes") can be attached to and detached from EC2 instances, but they are not a "share" or shared volume... so attaching a volume by ID becomes a non-useful idea after the first instance launched.
EBS volumes are hard drives. The analogy is imprecise (because they're on a SAN) but much the same way as you can't physically install the same hard drive in multiple servers, you can't attach an EBS volume to multiple instances (SAN != NAS).
Designing with a cloud mindset, all of your fixed resources would actually be on the snapshot (disk image) you deploy when you release a new version and then use to spawn each fresh auto-scaled instance... and nothing persistent would be stored there because -- just as important as scaling up, is scaling down. Autoscaled instances go away when not needed.
AWS has Simple Storage Service (S3) which is commonly used for storing things like documents, avatars, images, videos, and other resources that need to be accessible in a distributed environment. It is not a filesystem, and can't properly be compared to a filesystem, because it's an object store... but is a highly scalable and highly available storage service that is well-suited to distributed applications. s3fs allows an S3 "bucket" to be mounted into your machine's filesystem, but this is no panacea. That mechanism should be reserved for back-end process use, if you use it at all, because it's not appropriate for resources like code or templates, and will not perform as well for serving up content as S3 will perform if used as designed, with clients directly accessing it over https. You can secure the content through more than one mechanism, as documented.
AWS also now has Elastic File System (EFS) which sets up an array of storage that you can mount from all of your machines, using NFS. AWS provides the NFS server and the back-end storage. Unlike EBS, you do not need to know how much storage to provision up front, because it scales up and down based on what you've stored, billing you This service is still in "preview" as of this writing, so should not be used for production data.
Or, you can manually configure your own NFS server and mount it from the autoscaling machines. Making such as setup fail-safe is a bit tricky, though.