I use the following command in cli as below,
[mbelagali@mbelagali-vm naggappan]$ aws ec2 create-vpc --cidr-block 172.35.0.0/24 --no-verify-ssl --endpoint-url https://10.34.172.145:8787
/usr/local/aws/lib/python2.6/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py:769:
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
"Vpc": {
"InstanceTenancy": "default",
"State": "pending",
"VpcId": "vpc-ebb1608e",
"CidrBlock": "172.35.0.0/24",
"DhcpOptionsId": "dopt-a24e51c0"
}
And now I redirect the warnings using "2>/dev/null" so that i get only the json response.
Now I need to implement this using the python subprocess and hence tried the following option,
cmd = "aws ec2 create-vpc --cidr-block " + cidr_block + " --no-verify-ssl --endpoint-url " + endpoint_url
cmd_arg = shlex.split(cmd.encode('utf-8'))
p1 = subprocess.Popen(
cmd_arg,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output, error = p1.communicate()
Now in output variable I get is complete output including the warning messages how can I ignore the warning message as I do it in the shell script