My first python script is a file that creates an EC2 instance, and i am attempting have this script call a function from another python file i imported, the code is shown here:
import boto3
import amif2.py
session = boto3.Session(region_name='us-east-1')
ec2 = session.client('ec2')
response = ec2.describe_images(
Filters=[
{
'Name': 'name',
'Values': ['temp']
}
]
)
for each in response['Images']:
image_id = each['ImageId']
ec2_response = ec2.run_instances(
ImageId=image_id,
InstanceType="---",
SubnetId=---,
SecurityGroupIds=[
-
],
IamInstanceProfile={
'Arn': '---'
},
KeyName='ec2-creation-dev',
MaxCount=1,
MinCount=1,
TagSpecifications=[
{
'ResourceType': 'instance',
'Tags': [
{
'Key': 'Name',
'Value': 'temp'
},
]
},
{
'ResourceType': 'volume',
'Tags': [
{
'Key': 'Name',
'Value': 'temp'
},
]
},
]
)
print(ec2_response)
amif2.py.amifunc2()
inside this amif2.py is this function:
def amifunc2():
touch bashfile.txt
open("pythoncommandfile.txt","w+")
I tried both commmands, because my first script launches an EC2 instance, and inside this instance, the commands are in bash hence the touch file command, but i also wanted to test if it were the python command that creates the file in the instance. however after testing i get this error:
Traceback (most recent call last):
File "amibake7.py", line 2, in <module>
import amif2.py
ImportError: No module named 'amif2.py'; 'amif2' is not a package