Creating amazon ec2 windows AMIs using amazon sdk in java - amazon-web-services

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.

Related

How can I view files in EC2 instance?

I have just started learning about AWS. I am following along a tutorial and I have created a hello.txt file in EC2 using PuTTY on Windows. I wanted to know where I can see all the files listed in the EC2 instance on a GUI. I believe they are not stored locally on my computer; but I cannot find them on the AWS console either? Thank you.
PuTTY console screenshot
After some more AWS training, I found out that I can also see the files and folders in my EC2 instance in a "GUI" format using the Fleet Manager in AWS Systems Manager. The Systems Manager Agent must be installed in the EC2 instance and the instance must be given the appropriate permissions using IAM.
I wanted to know where I can see all the files listed in the EC2 instance on a GUI
Short answer:
Using a Windows PC to access an AWS EC2 you use PuTTY to navigate the file system. The hello.txt file you created is listed.
To open it you can do a cat hello.txt.
Official Answer:
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-2-install-gui/
The instructions get you to install the MATE desktop environment, a lightweight GUI based on GNOME 2 available as an extra for Amazon Linux 2.

Find what is making EC2 IMDSv1 calls on Windows Servers

I'm trying to get all our instances (all Windows based) upgraded to IMDSv2 and have been following the advice found here https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#instance-metadata-transition-to-version-2 and using CloudWatch to find instances making MetadataNoToken calls (i.e. using IMDSv1).
I've found several instances using IMDSv1 this way, but I can't work out how to find out what is making the calls from with the OS.
According to CloudWatch each server is making one call per minute to the IMDSv1 service.
The support article mentions upgrading any AWS SDKs or CLI tools, but the servers in question don't have seem to have any SDKs or CLI tools installed.
Each instance has the following AWS published tools installed on them:
Amazon SSM Agent
Amazon CloudWatch Agent
AWS Tools for Windows
EC2ConfigService
AWS PV Drivers
aws-cfn-bootstrap
I've updated the Amazon SSM Agent and the Amazon CloudWatch Agent to the latest versions. But I can't find any information about how to update the AWS Tools for Windows package.
I've also run TCPView from Sysinternals on the servers and tried to find what process is making calls to the 169.254.169.254 endpoint, but it doesn't seem to pick up any traffic to that address.
I'm reluctant to just disable IMDSv1 and do a scream test as they are production servers.
If anyone has any advice or guidance on how to find what is making the IMDSv1 calls it would be appreciated.
I figured it out in the end, using the £Windows Resource Monitor Network monitor" tool, I found the exectucable that was making the calls.
I've written up the proceess in this blog post:
https://www.greystone.co.uk/2022/03/24/how-greystone-upgraded-its-aws-ec2-instances-to-use-instance-meta-data-service-version-2-imdsv2/

Add more storage on a Amazon Web Service emulator for Windows on Mac

I'm using the Amazon Web Services emulator EC2 to run Windows server. I upgraded my instance type to the one with 4cores 16gb ram, and it worked well, but I need more storage to install visual studio. When I tried to upgrade to m5ad.xlarge to get the 150gb SSD, C: drive didn't expand like it was supposed to. I also tried adding a Volume, but that wouldn't work either. If anyone could give me a simple way or any external tutorials to complete this, that would be much appreciated, as the AWS Documentation solutions didn't work. Thanks!
Based on the comments, the issue was that the partition was not expanded. Following steps from the following AWS blog solved the problem:
How do I expand the Amazon EBS root volume of my Amazon EC2 Windows instance?

Creating an iso of a RHEL instance

I have an amazon ec2 instance with RHEL 7.3 on it. I would like to convert this into an iso so that I can migrate it wherever I want. What are the best tools to create an iso of a virtual machine. Or how do I clone/backup this VM so that I can restore it anywhere I want?
You can work with VM and AWS programatically via AWS CLI commands.
You want to get familiar with import-task and export-task commands.
The best place to start is by reading an official AWS guides for:
Exporting an Instance as a VM Using VM Import/Export
Importing a VM as an Image Using VM Import/Export
The key information you need to pick up from the guide is this quote:
"You can't export an instance from Amazon EC2 unless you previously
imported it into Amazon EC2 from another virtualization environment."
Yes, there are solutions, one of them linked by #Nicholas Smith. That being said, if you go the unofficial route you might end up in a dark alley where help might not be available. I highly recommend and warn here to not proceed with trying to clone EC2 into VM at this point. You will spend a lot of time with a huge risk factor for future.
For you to be able to achieve what you want, you need to create a RHEL VM using any VM software, you need to load this VM into AWS and then you will be able to work with VM in AWS making any necessary changes and export again for local or transportation needs.
As you are running a widely-used Linux distribution - RHEL, you can attempt to recreate your EC2 environment manually by launching a VM that runs the same kernel version along with the same package versions. From there, you can tarball what files you need from your production instance and copy them over to your on-premise site by using SCP/SFTP.
Just get your RHEL environment into VM locally and import to AWS and you set.
Clonezilla provides functionality to create images. Generated images can be converted to ISO files.
It doesn't seem to be something that Amazon promote as a service however the aws cli tools have an ec2-unbundle command for extracting from an AMI. There's a guide here on how to download and run an EC2 AMI locally by using it.
Caveat is it appears the ec2-unbundle command currently only works on Linux and not OS X or Windows.

Generate a limited list of AMI in EC2

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.