AWS EventBridge API Destination can't connect to EC2 private IP - amazon-web-services

My goal is to forward messages from EventBridge over HTTPS to an instance in EC2 running httpd server. The instance only has its private IP.
It turned out that the EventBridge's API Destination with its Targets and Connections works beautifully with external IPs, but no communication is happening to the Private IP. As part of the experiment Security is set to accept all https/http connections from all 0.0.0.0/0.
I am seriously considering EventBridge -> Lambda function with VPC bind -> EC2 Private IP.
But I am having that nagging feel that I maybe missing something with the API Destination, some network magic? An endpoint?
Any advice is welcome!

EventBridge over HTTPS to an instance in EC2 running httpd server. The instance only has its private IP.
You can't do this. HTTPS requires valid public domain with valid public SSL certificate. This in turn requires your instance to be accessible from the internet.
The instance itself can be private only, but in that case you have to front it with internet facing ALB, which will handle HTTPS for you.

Related

AWS EC2 Internet access from behind Load Balancer

Using Terraform to setup a VPC with two EC2s in private subnets. The setup needs to SSH to the EC2s to install package updates from the Internet and install the application software. To do this there is an IGW and a NAT-GW in a public subnet. Both EC2s can access the Internet at this point as both private subnets are routing to the NAT-GW. Terraform and SSH to the private subnets is done via Client VPN.
One of the EC2s is going to host a web service so a Classic mode Load Balancer is added and configured to target the web server EC2. Using Classic mode because I can't find a way to make Terraform build Application mode LBs. The Load Balancer requires the instance to be using a subnet that routes to the IGW, so it is changed from routing to the NAT-GW, to the IGW. At this point, the Load Balancer comes online with the EC2 responding and public Internet can access the web service using the DNS supplied End Point for the LB.
But now the web server EC2 can no longer access the Internet itself. I can't curl google.com or get package updates.
I would like to find a way to let the EC2 access the Internet from behind the LB and not use CloudFront at this time.
I would like to keep the EC2 in a private subnet because a public subnet causes the EC2 to have a public IP address, and I don't want that.
Looking for a way to make LB work without switching subnets, as that would make the EC web service unavailable when doing updates.
Not wanting any iptables or firewalld tricks. I would really like an AWS solution that is disto agnostic.
A few points/clarifications about the problems you're facing:
Instances on a public subnet do not need a NAT Gateway. They can initiate outbound requests to the internet via IGW. NGW is for allowing outbound IPv4 connections from instances in private subnets.
The load balancer itself needs to be on a public subnet. The instances that the LB will route to do not. They can be in the same subnet or different subnets, public or private, as long as traffic is allowed through security groups.
You can create instances without a public IP, on a public subnet. However, they won't be able to receive or send traffic to the internet.
Terraform supports ALBs. The resource is aws_lb with load_balancer_type set to "application" (this is the default option).
That said, the public-private configuration you want is entirely possible.
Your ALB and NAT Gateway need to be on the public subnet, and EC2 instances on the private subnet.
The private subnet's route table needs to have a route to the NGW, to facilitate outbound connections.
EC2 instances' security group needs to allow traffic from the ALB's security group.
It sounds like you got steps 1 and 2 working, so the connection from ALB to EC2 is what you have to work on. See the documentation page here as well - https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Scenario2.html

Aws - acm certificate bind to ec2 instance

I have an application and api running/hosted in same aws ec2 instance . I have enabled ssl cert using acm via load balancer for application domain . However , my api is exposing via ec2 public ip i.e http://ec2ip. In such scenario how can I bind ssl cert in IP address i.e https://ec2ip ?
You ideally don't want to have a public IP on your load-balanced EC2. You can achieve this by placing the EC2s in a private subnet. This will need bastion server in order to SSH though.
If you absolutely want HTTPS on an IP address, this SO page is the answer. If you do set that up, make sure that it is an elastic IP address.
If you have load balance you shouldn't directly access your instance using public IP. As per AWS documentation you shouldn't even have a public IP address for your instance.
someday if you run security assessment to your aws environment, AWS Foundational Security Best Practices v1.0.0 will be failed because of public IP.
EC2 instances should not have a public IPv4 address
This all about security concerns. Typically, only a Load Balancer is exposed to the Internet.
Back to Basics: Protecting Your Network in the Cloud

AWS EC2 not accessible from public IP

My application is working fine on the Amazon EC2 Windows Server. But when I am trying to access the same through the elastic public IP, it is not accessible. I have seen the inbound configurations and the ports(HTTP,HTTPS,SSH) are enabled. Infact, I added a rule to All Traffic from Anywhere. But no success.
Firewall ports are open in host server. The URL is accessible from private IP from other EC2 machines in same network
http://3.45.54.89:8080/My-App/ ----> Public IP- Not Working
http://10.0.2.23:8080/My-App/ ----> Private IP - Working
Please guide. Stuck Badly in this
The fact that you can access the port from within the network points out that you indeed have a rule somewhere in the VPC that is blocking the connection from outside the network.
Here are the components you need to access a resource inside a VPC from outside the VPC:
Internet Gateway: This is the entry point into the VPC. Seems like this is already working as expected as you can access the instance in the first place.
(optionally) Bastion host: If the resource you are trying to connect to is in a private subnet you need a bastion host in the public subnet. Read more about it here.
NACL: If you have not changed the defaults, this should allow the requests to flow through. Note that NACL are stateless i.e. you need to allow both inbound and outbound.
Security Group: As the final layer, the security group should allow the traffic on the ports, to the appropriate cidr block.
Based on the scenario you have described, my guess is that your instance is in a private subnet. If it is, then you need to route the requests through something in the public subnet.
Edit the firewall ports for an IIS website in Windows Server. if the iis apps are not in the inbound list please add them and try again.
https://www.youtube.com/watch?v=YQcklFuWrcw

I have a server running on ec2 but I cant connect to the localhost 8085. Any suggestions?

I have a server running on ec2 but I cant connect to the localhost 8085. Any suggestions ?
Check to make sure your setup has the following:
There is an elastic IP attached to the instance, or it has a public IP address.
The security group allows incoming traffic on the correct port.
The network ACL of the subnet that allow for the needed inbound and outbound traffic, or you're using the non-existent/default ACLs, which allow all inbound/outbound traffic.
An Internet Gateway is in the same VPC as the instance.
There is a rule in the subnet's route table that sends internet-bound traffic to the Internet Gateway.
You may also find this AWS article helpful for using the Internet Gateway in your VPC.

How to set up SSL for ELB to E2C in private subnet of VPC

I can't seem to find any documentation that deals with this scenario in a VPC.
I have an EC2 in a private subnet.
I have an internet facing ELB in a public subnet
ELB has SSL cert and accepts https connections
What are the steps to set up https communication between ELB and EC2? If https is terminated at ELB do i need to set up certs for ELB > EC2?
Thanks in advance,
So it turns out this setting is on the ELB but you only see it on creation. Once the ELB has been created it's no longer visible.
When creating the ELB you need to select 'Backend Authentication' and then you have the option there to upload your SSL certs. If the SSL is incorrect for whatever reason than any secure health checks will fail.
Under this scenario SSL is terminated on the ELB and then the ELB initiates a new SSL connection with the backend servers.
I don't see how this is any different from any other ELB setup. The fact that the EC2 instance is in a private subnet has no bearing on the SSL certificate.
If you want communication between the ELB and the EC2 instance to use SSL, then you would need to install an SSL certificate on the EC2 instance. How you do that depends entirely on what web server or other server software you are running on the EC2 instance.
If https is terminated at ELB do i need to set up certs for ELB > EC2?
If you only care about securing communication from the internet into your VPC, then no you don't need this. If you care about securing the communication within your VPC then you would need this. I'm having trouble thinking of a reason that you would care about that, since the communication between the ELB and the EC2 instance is entirely contained within your VPC.
Wouldn't you just terminate the SSL on the ELB and then use the ELB itself to choose which underlying web server traffic is routed to (via Http)?
If that's in a private subnet (which it should be) then you,ll have needed to set up the route tables / NACLs and security groups accordingly (which you would need to do anyway) to ensure the http traffic can be routed accordingly inbound and outbound