I am trying to create an EC2 instance using boto3 client.run_instances(**parameters) method. This is the value of my parameters:
{
"ImageId":"ami-XXXXXXXXX",
"InstanceType":"m4.large",
"KeyName":"my_key",
"UserData":"Content-Type: multipart/mixed",
"Monitoring":{
"Enabled":false
},
"MaxCount":1,
"MinCount":1,
"IamInstanceProfile":{
"Name":"proxyIp-YYYYYYYY"
},
"NetworkInterfaces":[
{
"DeviceIndex":0,
"AssociatePublicIpAddress":true,
"Groups":[
"sg-09999999fe111"
],
"SubnetId":"subnet-06XXXXXXXXX"
}
],
"PrivateIpAddress":"AA.BB.C.DDD",
"EbsOptimized":true
}
However the stack is failing on creation of an ec2 isntance with an error :
An error occurred (InvalidParameterCombination) when calling the RunInstances operation: Network interfaces and an instance-level private IP address may not be specified on the same request
Could let me know what is missing. I have checked the parameters they all looks to be fine.
CodePudding user response:
It looks like you can request a Private IP address within the NetworkInterfaces
block:
"NetworkInterfaces": [
{
"PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal",
"PrivateIpAddress": "10.0.0.157",
"SourceDestCheck": true,
"Status": "in-use",
"SubnetId": "subnet-04a636d18e83cfacb",
"VpcId": "vpc-1234567890abcdef0",
}
],