New EC2 instance based on another EC2 AMI is not working properly

0

I have an ec2 instance which is serving backend-logic for my application and it is not part of a CloudFormation stack. I wanted to create a new stack with new VPC and Subnet and Security group and Autoscaling group which launch an ec2 instance based on the AMI of the former ec2 instance i mentioned before. I created the CDK app and deployed it. But all the requests to any endpoint is failing with Error: connect ECONNREFUSED I don't know how to troubleshoot this issue., or how to identify where the issue is. The new ec2 instance which is launched from the CDK app is based on the AMI of the former ec2 instance. what might be wrong ?

Troubleshooting I have done :

1- Security Group Rules: I ensured that the security group attached to my EC2 instance allows inbound traffic for HTTP traffic on port 80.

2- Ensured that the subnet in which my ec2 instance resides has a route to an internet gateway. ( ec2 instance is in a public subnet) and also pinged a sample URL and received a response.

I am using the ec2.GenericLinuxImage API to create the new ec2 instance

 const asg= new autoscaling.AutoScalingGroup(this,'autoscaling-cdk',{
      vpc,
      associatePublicIpAddress:true,
      instanceType:ec2.InstanceType.of(ec2.InstanceClass.T3A,ec2.InstanceSize.SMALL),
      keyName:.....................,
      machineImage:new ec2.GenericLinuxImage({'region':'ami-ID'}),
      securityGroup,
      vpcSubnets:{subnetType:ec2.SubnetType.PUBLIC},
      desiredCapacity:......
    })

Note :

1- the ec2 instance launched from CDK code is launched in a region that is different from the source ec2 which the AMI is based on , and there is an RDS instance involved which happens to be in the same region & VPC of the Source Ec2 instance which the AMI is based on. Do I need to create a VPC Peering taking into consideration that at time of testing the new ec2 instance I was allowing all inbound traffic in the RDS instance.

2개 답변
2
수락된 답변

Yes, if your new EC2 instance launched from the CDK code is in a different region than the source EC2 instance and the RDS instance, you will need to establish a VPC Peering connection between the two VPCs to allow communication between the new EC2 instance and the RDS instance.

VPC Peering is a networking connection that allows you to route traffic between two VPCs, even if they are in different regions or different AWS accounts. This way, your new EC2 instance in the new region can communicate with the RDS instance in the original region and VPC.

Useful Source:

profile picture
전문가
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
0

Thanks So Much it worked

Mahmoud
답변함 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠