Runnable jar in AWS EC2 - amazon-web-services

I have a requirement to run a runnable jar from AWS lambda. One option is to create a docker and use ECS to achieve the desired result.
I am looking for an alternative approach using EC2. Is it possible to deploy a runnable jar in EC2 and then invoke it from AWS Lambda?

Yes it's possible using EC2 Run Commands. You could use your favorite AWS SDK flavor (Java, Python, etc) to run a command on your EC2 instance from your Lambda function. Here's a good tutorial: http://docs.aws.amazon.com/systems-manager/latest/userguide/run-command.html

Related

How to deploy from Cloud9 to EC2?

I have my app developed in Cloud9, and I would like to use the terminal with GIT commands to deploy my app to a EC2 instance. The objective is to make the app run in the EC2 instance.
Is it necessary to deploy the app to a EC2 instance, or is it already in a EC2 instance and I just have to open the URL of the app?
My cloud9 environment is in a region and my EC2 Instance is in another region (I'm telling this just in case it changes something in the process).
I already did it to Heroku, but I can't see how does it work to a EC2 instance.
Thank you very much !
If you want to deploy your app to an EC2 instance from the Cloud9 console, you have a couple of options. Please note, you only need to use one of these options, not all of them. I would generally recommend option #1 for your case based on your original question.
Use AWS amplify instead of EC2 (Amplify is Amazon's version of Heroku)
Use the AWS CDK client, and specifically, you'll want to look at Instance and either utilize userData or CodeBuild to build your app and deploy to EC2.
Use the AWS client to deploy Cloudformation templates (this is the lower-level version of option #2 and will require more boilerplate)
Connect your Git repository to AWS CodePipeline and run a CI/CD flow to deploy it to EC2 on every commit to the main/master branch (this is fairly complicated)
The most important thing to understand is that Cloud9 is simply an IDE (integrated development environment) that is deployed to an EC2 instance that is managed by AWS (not you). Cloud9 is not a tool for actually deploying code (you'll need to use one of the options I mentioned above for that).

build and push docker image to AWS ECR using lambda

Is it possible to automate building a docker image from code committed into github (no tests involved) and then push it to AWS ECR using a lambda function?
you cannot do it just with lambda as lambda is not really a suitable execution environment for the docker daemon (necessary to build the images), however you can use lambda + sns to trigger an endpoint that could point to a service you developed, hosted on ec2 that would trigger the docker build command after a git clone (you can use something similar to python's fabfile.org or a framework that allows you to execute server commands).
You sure can extend this idea on perhaps bringing the ec2 build machine up with some ami that automates this, etc....
The big point here is that you don't really have control over what's provisioned in lambda, so you need ec2.

automate exe installation in AWS ec2 instances

Is there any way to install exe/MSI agents in AWS EC2 instances in an automated way?? In specific, I am looking for a counterpart of Azure's Custom Script Extension. [Free of cost]
Scenario:
I want to install BigFix and Datadog agents on 1000 Ec2 instances, this is a one time job, so I am not looking for any solution that involves Chef / Puppet, etc.,
Yes, you can pass a script to the instance that will be executed on the first boot (but not thereafter). It is often referred to as a User Data script.
See:
Running Commands on Your Windows Instance at Launch - Amazon Elastic Compute Cloud
Running Commands on Your Linux Instance at Launch - Amazon Elastic Compute Cloud
If you wish to install after the instance has started, use the AWS Systems Manager Run Command.

Powershell Automation in ec2

We are trying to automate running of multiple powershell scripts in AWS EC2 instance. Any suggestion how this can be done. These execution has to be sequential.
In order to configure state on a fresh EC2 instance, you can use 'User Data' in order to:
a. Fully provision and configure state using powershell, see:
http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html#instancedata-add-user-data
b. Install an agent for a configuration management tool such as Puppet, Chef, Ansible (as mentioned in the comment above). An example of provisioning stock Window's AMI's can be followed here: http://blog.rolpdog.com/2015/09/manage-stock-windows-amis-with-ansible.html
If you wish to trigger scripts on an existing Amazon EC2 instance (or a whole fleet of instances), also consider Running PowerShell Commands or Scripts with Amazon EC2 Run Command.

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