Unable to connect internet on EC2 instance


I have created an ec2 instance using tf CDK. i am trying to run a command on this instance which needs internet access but it is not able to connect but when i create an instance manually on AWS with same properties, it is able to connect. i am using NAT gateway to connect with internet. is there any specific property i am missing when creating instance with terraform ?

Hi @vishalailani :wave:

Have you created the required ACL rules and configured the VPC subnets accordingly?
Here are some docs from AWS on this topic: Enable EC2 Instances to Access the Internet Using a NAT Gateway

Hi @ansgarm , instance created manually within same security group and subnet with the same ami is able to connect but instance created with terraform not.

is there anything i need to specify in config when creating with TF.
i am passing these arguments for now:
ami: string,
instanceType: string,
subnetId: string,
vpcSecurityGroupIds: string ,
availabilityZone: string

Hi @vishalailani!

If you create an instance via the AWS Console Wizard, it might have set defaults which it didn’t tell you about.
You could compare the properties of the instance that can connect in the AWS Console to the one your created via CDK for Terraform (also look at its properties in the AWS Console. Maybe you can spot the difference there.

Hi @ansgarm , did check all properties with state file as well but not getting anything related to internet access through NAT gateway. can you please suggest which config attributes may have a role in internet access ?

Hi @vishalailani,

have you compared the security groups & subnets that are connected to the two EC2 instances?

Hi @ansgarm , Yeah, i compared and found the diff in properties of subnet. It is resolved now. thanks.

Hi @vishalailani!