In security group(inbound rules) of ec2 instance i have opened mongo port to security group of lambda function EC2 inbound rules screenshot
In lambda function also i have selected vpc,subnets and security group. Lambda vpc configuration screenshot
Also i have configured NAT gateway for vpc. Still i am not able to access mongodb