Generate a limited list of AMI in EC2 - amazon-web-services

While creating an instance in EC2 using JAVA SDK, is it possible to get the user to select an AMI Instance out of a limited list? Is there an API to display a set of AMIs in EC2??

Yes There is. You want to retrieve a list of AMIs depending on your search criteria.
I am not a java guy. But this functionality is available in :
AWS CLI
AWS Ruby SDK
The closest I found for AWS JAVA SDK is this.
There are AWS APIs available. So just figure out a JAVA way of doing it.

Related

How to retrieve the instance type of AWS EC2 programmatically

I have a Java service running on AWS EC2, I guess I could probably
use AWS SDK to retrieve the instance type of current node.
I am wondering is there any other way to achieve the same goal without using SDK (there are some reasons I don't want my package become dependent on AWS SDK).
For example, we could query /proc to know the OS type or CPU info on Linux, is there any similar way to achieve this? Thank you.
The instance type is available in the instance metadata.
$ curl http://169.254.169.254/latest/meta-data/instance-type
t3.small

AWS service to deploy a machine with default security groups, alarms, etc.?

I am looking to provide my software setup to others for use on AWS with as few manual steps as possible. I can create an AMI with my software pre-installed and configured rather than just an installer which cuts out several issues (badly sized disks, people picking wrong/unsupported distro for my compiled binary, etc.) but this does not bundle the config for network interfaces, alarms, or other related Amazon services.
Does Amazon have a service/mechanism that will such features? I know of launch templates but these are per-region, per-account and need to be created after groups etc. have been added manually.
I know Amazon have API's for all this, but before turning to third parties or my own script I want to be sure that Amazon has no portable template type thing that can be provided and they simply launched in the console.
You can create your AMI with your software pre-installed and publish them to all the available regions(AWS marketplace/ public access).
Later use Cloud formation template which will include creation of aws resources needed for your application to run including launching instance using your AMI id's for each region and the instance launch uses the ami from the corresponding region. This way your customers can just use the cloudformation template and all prerequisites will be met.
In terms of having your AMI ID in the cloud formation template and using it based on the region in which it is launched can be achieved using the Mappings section in Cloud formation. Hope that helps

Is there any API to automatically spin up AWS server

I might be naive but looking for a good solution to automatically spin up an AWS server with an API.
The use case is to create AWS EC2 instances on a click and maintain the deployments. Ansible is a probable candidate but looking for the core solution of spinning up a new EC2 machine.
Appreciate your help.
Rather than directly calling an API (eg from Java, .Net, Python, etc), you can also use the AWS Command-Line Interface (CLI).
The command you want is run-instances, which will launch a new Amazon EC2 instance.
See: AWS CLI documentation for run-instances

Can I use AWS CloudFormation with a custom AMI?

I want to use an AMI that have not been created from a snapshot. The AMI was created using a virtual machine and then I used CLI tools to create the instance and the AMI.
This instance have installed cloud-init. Could I use this AMI to create instances using cloudformation?
Do I need to install more software to use that service?
Thanks!
Yes, definitely, that is a very common use case:
Amazon Web Services (AWS) publishes many Amazon Machine Images (AMIs)
that contain common software configurations for public use. In
addition, the AWS developer community has published many custom AMIs.
You can also create your own custom AMIs so that you can quickly and
easily start new instances that have everything you need for your
application. For example, if your application is a website or a web
service, your AMI could include a web server, the associated static
content, and the code for the dynamic pages. After you launch an
instance with this AMI, your application is running and ready to
accept requests.
https://s3.amazonaws.com/cloudformation-examples/BoostrappingApplicationsWithAWSCloudFormation.pdf
Should you plan to use Cloudformation:Init inside your template to add additional configuration when your instance will start, be sure to install cfn tools as well (cfn-init, cfn-hup, cfn-signal...)
More details about Cloudformation:Init : http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html
How to install cfn helper scripts : http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-helper-scripts-reference.html
Yes.
When you are specifying the instance in the cloud formation script you can use "ImageID": "" <- put in the AMI ID
ImageId
Provides the unique ID of the Amazon Machine Image (AMI) that was assigned during registration.
Required: Yes
Type: String
Update requires: Replacement

Creating amazon ec2 windows AMIs using amazon sdk in java

I am writing an application which would enable my company's future clients to be able to launch Amazon aws instances with Windows OS. Hence, I would want to create windows AMIs first. The article below gives a step by step approach for creating EBS-backed windows AMIs using Amazon AWS console.
http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/Creating_EBSbacked_WinAMI.html
But when I tried looking up the methods provided by CreateImageRequest API provided by Amazon SDK, I couldn't quite figure out how to replicate the AWS management console process for creating a windows image in Java. I exhausted my google searches and I came up empty. Has anyone tried this? Is this even possible at all to create Windows images through Amazon SDK?
I found that CreateInstanceRequest API has an option to specify the OS types but the options are limited to Amazon Linux or Ubuntu 12.04 LTS. The documentation for CreateInstanceRequest is below:
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/opsworks/model/CreateInstanceRequest.html
I would appreciate any useful link or code snippet. Thanks.
I don't completely understand what you are trying to achieve.
Do you want to start an instance in EC2 or with OpsWorks because your second link points to the OpsWorks documentation.
OpsWorks dosen't support Windows right now.