How to assign EC2 instance to aws autoscaling group with terraform? - amazon-web-services

I am trying to create a terraform script to assign a new autoscale group to our existing EC2 instance. I based my script using the following terraform documentation (https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html). I have a data method pulling the Ec2 instance by filters. Just stuck on how to assign the instance ID to the "aws_autoscaling_group". The docs do not provide a variable for this, however, on the GUI you can click on a running instance to assign it. What have you all done to help resolve this?

Related

How to attach existing EC2 instances to auto scaling group in terraform?

I created 2 EC2 instances using terraform.
Is there any way to attach them into auto scaling group using terraform?
I didn't find anything about this in the docs :/
I don't want to create them within the ASG, only attached them.
As I said the instances were generated by terraform script as well as everything else (ASG, SG...).
Thank you
Unfortunately this is not possible via Terraform directly
However you could run the attach-instances AWS cli command.
If this needed to be performed in terraform you could put the command into a local-exec resource.

How to add EC2 instance to ECS cluster using AWS Node SDK

I am trying to programmaticly create a ECS cluster with EC2 instance in it. As far as I understand I should first create an ECS cluster , than EC2 instance and then register instance using this method :
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ECS.html#registerContainerInstance-property
Is it how I should do it? Which arguments are mandatory? How to get instanceIdentityDocument and instanceIdentityDocumentSignature?
thanks
I would use the User Data of the EC2 instance to launch the instance directly into the ECS cluster. This is the User Data you'll want to use:
#!/bin/bash
echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config
The details of this are described in the AWS docs. You can also use this user data in an Auto Scale Group Launch Configuration.
Apart from that, it might be worth it to look into languages that where made to provision infrastructure, like Terraform (also for AWS) or CloudFormation (specifically for AWS).

How to specify Ec2 Instance Attributes in a AWS::EMR::Cluster CloudFormation Template?

Very new to AWS and looking at EMR and hoping for some direction and information here. I want to create a cloud formation template for EMR using AWS:EMR:Cluster, however I don't see a way to specify my EC2 Attributes like, Security Groups and EC2 Instance profile.
I am looking at the resources here: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-emr-cluster.html
Can you direct me how this accomplish this from a cloudforatemplate?
I saw the AdditionalInfo do I add the Ec2 JSON template there ?
You should configure the Instances property. Each instance is a JobFlowInstancesConfig.
For instance profiles, provide a JobFlowRole. All EC2 instances in the EMR cluster assume this role.

Updating user-data for EC2 instances under an autoscaling group

I want to modify / update the user-data for an EC2 instance. This is attached to an autoscaling cluster.
I understand that the instance needs to be stopped before the user-data can be updated. The problem I am facing is, when I stop the instance to update user-data autoscaler automatically brings a new instance back up.
Is there a way to update user-data without removing the EC2 instance from the autoscaling group?
For instances in an autoscaling group, the user data is generally updated by creating a new launch configuration with your new user data.
Your AutoScaling group should be associated with a launch configuration already. There is an easy option to copy launch configurations from the AWS web console that will replicate all of your existing options. Simply find this launch configuration, copy it, and then replace the old user data before you save the new configuration.
Once the new launch configuration is created, apply it to your autoscaling group. You can begin using it immediately by increasing the desired size of the group to launch a new instance with the new configuration, and then detach the old instance once you're satisfied that the new instance (and any hosted applications) are operational.
You can likewise use this method to change any property of a launch configuration without causing an interruption to your application.
Further Resources:
AWS Documentation - Creating a Launch Configuration
The only way can achieve this is by disabling autoscaling temporarily using programmatic invocation using aws sdk.
You can restart the servers after the autoscaling is disabled.
(node API http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/AutoScaling.html#suspendProcesses-property)

How to see ec2 instance details that are created by data pipeline

I have created an ec2 instance using data pipeline. TerminateAfter field value was set to 2 hours. How can i verify the created ec2 instance details(like ip, java versions...) using aws ec2 console?
You will see the instance attributes like ip, region etc., in the dashboard. But if you want system specific information like java version, you have to ssh into the created instance. Make sure you are looking for the instance in the correct region.