How to find the region of AMI? - ruby

In my Project I have one AMI Image-id. I want find out in which region this AMI runs? Can anyone please explain, how to get it without going to AWS console.

use AWS ec2 describe images function http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeImages.html
using the AWS command line tools.
alternatively you can use Ruby sdk for AWS
http://aws.amazon.com/sdkforruby/

Related

Azure Devops Deploy Docker image to ec2 instance

I hope somebody can direct to the best approach to solve this matter.
I have an azure account on which I have an azure container registry holding my docker images. Just for personal education purpose I want to try and deploy one of azure docker images into a aws ec2 instance.
Reading some aws documentation, I understand that I need to create a ecr container and with azure DevOps, using the service connection to build and deploy the docker images to ecr, this seems to be pretty straight forward. But after this step its plain darkness as I cannot find a best approach on how to implement a continuous delivery every time there is a new docker image in my ecr.
One of the solutions I thought and found, is to install an azure DevOps agent on the ec2 to run a docker pull but I am not 100% sure about if this is the best approach.
So I am asking to you experts to enlighten me about this and I do apology for the basic question.
Thank you so much in advance for any help you can provide, and please if my question is not 100% clear, do not hesitate to ask more infos.
You should be able to authenticate to your Azure Container Registry instance from EC2 using standard docker login command. You do not even need Azure DevOps agent for that, since you should be able to configure regular service principal with set of standard docker registry credentials.
Then you can pull and use your images normally.
It is absolutely not required to replicate your images in the ECR.
Unless you want to do full ECS. Use a shell script to do what you would do manually on the EC2 command line.

How to execute some script on the ec2 instance from the bitbucket-pipelines.yml?

I've bitbucket repository, bitbucket pipeline there and EC2 instance. EC2 have access to the repository ( can perform pull and docker build/run)
So it seems I only need to upload to EC2 some bash scripts and call it from bitbucket pipeline. How can I call it? Usually ssh connection is used to perform scripts on EC2, is it applicable from bitbucket pipeline? Is it a good solution?
two ways to solve this problem, I will leave it up to you.
I see you are using AWS, and AWS has a nice service called CodeDeploy. you can use that and create a few deployment scripts and then integrate it with your pipeline. Problem with it is that it is an agent that needs to be installed. so it will consume some resource not much but if u are looking at an agentless design then this solution wont work. you can check the example in the following answer https://stackoverflow.com/a/68933031/8248700
You can use something like Python Fabric (its a small gun) or Ansible (its a big canon) to achieve this. it is an agentless design works purely on SSH.
I'm using both the approaches for different scenarios. For AWS I use CodeDeploy and for any other cloud vendor I use Python Fabric. (We can use CodeDeploy on other than AWS but then it comes under on-premise pricing for which it charges for per deployment)
I hope this brings some clarity.

Amazon AWS ElasticBeanstalk custom AMI

I am trying to use a custom AMI in AWS Beanstalk. I manually launched a default Amazon ElasticBeanstalk image in EC2 (ElasticBeanstalk-Tomcat7-32bit-20110913-1132 (ami-278e4c4e)) and created my custom AMI from that. I then go to ElasticBeanstalk, launch an Environment and once it's up and running, I switch to this custom AMI in the Environment's configuration.
The health status is green. But my webapp does not get deployed on the instance:
[root#ip-***-***-***-*** ~]# ls -l /opt/tomcat7/webapps
total 0
Tomcat is running:
[root#ip-***-***-***-*** ~]# /etc/init.d/tomcat7 status
Tomcat 7 is running.
I am puzzled about why my app does not get deployed. Does anyone know what's going wrong?
well, the Beanstalk AMIs use a init script to copy your application from S3, and deploy it to the container (Tomcat).
I would recommend:
1. Take a look on CloudInit logs at: /var/log/cloud-init.log.
2. If everything looks fine (or even empty), edit the script at /etc/sysconfig/cloudinit to add some traces just to check if the CloudInit script is executed, or is failing at some point.
I'm sorry no being able to give you a better help, but is hard from here to know what is happening!
What I normally do, is launch a Beanstalk Instance (not a Instance with a Beanstalk AMI), then I do the modifications on that instance, and to finish I create my custom AMI to do what you are trying to achieve.
I meanwhile figured out the problem. When you create your own AMI from one of the Amazon predefined Beanstalk images, and you don't actually make any changes to the file system (install anything, create files, etc.), AWS will NOT create a new snapshot while creating a custom AMI. The created AMI will not work in Beanstalk then.
As long as you make any changes to the default image before you create your own custom AMI, everything should work fine.

Want to Deploy Task on AWS

I want to deploy my task (which is implemented in Hive) on AWS EC2.
I just read about the AWS, I came to know that we can create our own environment on EC2.
I am completely new to AWS. So I don't know anything about it
How to create such environment there?
I also read that we can import our VM image?
But for that the connector needed for it having .ova extension. If I download it, How to install it? (having .ova extension)
All this things is possible on AWS Free instance (creating our own environment and also VM Import)
Please guide me through this if you know about this.
To setup an instance on Amazon EC2 you might want to go through following guide: http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/Welcome.html
Regarding importing your own VM image, you might want to go through following link: Amazon EC2 VM Import. They do support importing images of VMWare, Hyper V etc. In the link you will see 2 options how you can import your image:
Command line option
Amazon EC2 VM Import Connector for VMware vCenter
Personally I know that using command line option has option to provide image file in format specific to your virtual machine software. You can see details of command line options at ec2-import-instance API reference.
Importing an image is free as there is no charge for data coming in to AWS. But there is a change for storing an instance created using image import. Every service has some sort of charge associated with it like per hour charge for instance until instance is up. So those charges are applicable regardless you are importing your image or not. Please see Amazon EC2 pricing at EC2 pricing

Can't generate a working customized EC2 AMI from Amazon Beanstalk sample appl

As I want to install Jenkins (ex-Hudson) to operate my continuous integration processes on AWS Beanstalk, I need a custom AMI because some parameters in Tomcat & Linux have to be changed for Jenkins
I run the process of installing and customizing the instance started initially by Beanstalk until the end and Jenkins works like a charm on it.
But, what I can't do is reuse the AMI that I generated at the end of my customization: the health check done by BeansTalk doesn't see the EC2 instance although Beanstalk started it and it works fine.
In order to understand my issue, I reduced my failing process to the following:
a) I create a new BT application / environment based on sample provided by Amazon (only parameter that I had is a keypair to SSH my EC2 instance)
b) when the EC2 instance is started, I use the EC2 to flash the AMI
c) I modify the BT env config by changing the original AWS Ami (id: 100fff79 - Tomcat 6 64 bits) by the 1 that I genrated in (b)
d) the BT rebuilds when I change the ami id
e) the rebuild restarts the EC2 instance.
f) It starts fine (can ssh to it) but the health checking fails and my env turns to red status.
Can somebody replicate this process and tell me what I am doing wrong ?
(I would like to use the AMI of (b) as starting point for my Jenkins customization.?
Additional info that I can provide:
when ssh-ing to the EC2 instance, a grep for apache, java, thin & bluepilld as described at bottom of https://forums.aws.amazon.com/thread.jspa?threadID=59027&tstart=25 shows that the 4 expected processes disappeared. Hence, the failure.
Please, help !
regards
didier
will answer my own question: the right way to obtain a working customized ami for Beanstalk is not to try to flash a running instance launched by Beanstalk but rather start the template ami for Beanstalk (ami-100fff79 for Tomcat 6 64 bits in my case) from EC2 console and customize it from there, flash it and you're done.
You can then "edit configuration" for your BT environment by changing the ami to the new one and it works fine.
regards
didier
If you give more details, this is a feature I'm planning for version 0.3.0 of Beanstalker, my set of Maven plugins for automating maven deployments to Elastic Beanstalk and Elastic MapReduce. It is available at http://beanstalker.ingenieux.com.br/
Actually, the placeholders are there, but I haven't still done full testing of that. Are you willing to try and give help and advice?
You should be able to create a customized AMI from a running instance as long as you delete /opt/elasticbeanstalk/srv/hostmanager/db/hostmanager.db on the instance before building the new AMI. I keep seeing people say "it can't be done, you need to start a clean instance outside of Elastic Beanstalk" and that's bunk. I've done it.
A full write-up of what I've done to customize my install is here: http://stormerider.com/blog/2012/08/16/building-an-ubuntu-ami-with-elastic-beanstalk-support/ -- some of it may not apply to you, some of it may.

Resources