amazon-ec2

Find EC2 instances that not equal to X – AWS CLI

Find EC2 instances that not equal to X – AWS CLI Question: I’m looking to find instances that is not equal to platform "Windows" and tag them with specific tags. For now i have this script that is tagging the instances that are equal to platform "Windows": import boto3 ec2 = boto3.client(‘ec2’) response = ec2.describe_instances(Filters=[{‘Name’ …

Total answers: 2

How to Stop and Start EC2 Instance using boto3 and lambda Function

How to Stop and Start EC2 Instance using boto3 and lambda Function Question: I want to start and stop EC2 instances using Lambda Function I am able to start and stop EC2 instances using the Instance ID but How can I do the same for Instance name, I am trying to do this because my …

Total answers: 2

How to automatically assign/remove Elastic IPs to EC2 Instances upon start/stop

How to automatically assign/remove Elastic IPs to EC2 Instances upon start/stop Question: I am stopping my EC2 instances at night and restart them in the morning using CloudWatch Rules, however the public DNS/IP changes when we restart. I want to use Elastic IPs and associate the with the instances. I have read that we need …

Total answers: 1

Downloading a file from S3 to local machine using boto3

Downloading a file from S3 to local machine using boto3 Question: I’m trying to use a Python script to automate downloading a file from AWS S3 to my local machine. The Python script itself is hosted on Ubuntu (AWS EC2 instance), so it’s not recognizing a directory on my local machine. Here’s my code: import …

Total answers: 2

Reading in a file from Ubuntu (AWS EC2) on local machine?

Reading in a file from Ubuntu (AWS EC2) on local machine? Question: I have a Python script which I’m running on AWS (EC2 instance with Ubuntu). This Python script outputs a JSON file daily, to a directory in /home/ubuntu: with open("/home/ubuntu/bandsintown/sf_events.json", "w") as writeJSON: file_str = json.dumps(allEvents, sort_keys=True) file_str = "var sf_events = " + …

Total answers: 5

How to check if an ec2 instance is running or not with an if statement?

How to check if an ec2 instance is running or not with an if statement? Question: I have an instance-id of an ec2 instance. How to check if that ec2 instance is running or not using an if statement? I am using Python and Boto3. Asked By: jbot || Source Answers: Using the boto3 Resource …

Total answers: 3

Django TemplateDoesNotExist at / debug_toolbar/base.html after deployiing to EC2

Django TemplateDoesNotExist at / debug_toolbar/base.html after deployiing to EC2 Question: I am trying to deploy a Django app on EC2 Instance. I had put my EC2 instance in the Allowed_Host correctly. but it kept giving me a Disallowed_Host error. I have been trying to fix that but Now I get the. Django TemplateDoesNotExist at / …

Total answers: 3

How to use Boto to self-terminate instance its running on?

How to use Boto to self-terminate instance its running on? Question: I need to terminate an instance from an AutoScalingGroup as the policies ASG has are leaving the scaled out instances running longer than desired. I need to terminate said instance after its done running a python process. The code already uses Boto to access …

Total answers: 2

Getting Killed error in aws but works in Mac

Getting Killed error in aws but works in Mac Question: When I try to run the following pickle program in aws ubuntu instance, I am getting ‘killed’ message and it is not generating pickle. However the same works when I try it in my local machine (Mac). I am using python3 to run the program: …

Total answers: 2

InvalidInstanceId: An error occurred (InvalidInstanceId) when calling the SendCommand operation

InvalidInstanceId: An error occurred (InvalidInstanceId) when calling the SendCommand operation Question: The below is the code which i am running from python to execute commands in aws ec2 instance import boto3 ec2 = boto3.client(‘ssm’,region_name=’us-east-1′,aws_access_key_id=’xxxxxxxxxxxxxxx’,aws_secret_access_key=’xxxxxxxxx’) a = ec2.send_command(InstanceIds=ids, DocumentName=’AWS-RunShellScript’, Comment=’abcdabcd’, Parameters={“commands”:[“ifconfig”]}) But it is giving the below error InvalidInstanceId: An error occurred (InvalidInstanceId) when calling the …

Total answers: 4