Executing Spring boot jar in Amazon EC2 instance - amazon-web-services

I am new to amazon EC2 instances. I am able to deploy my jar in EC2 linux instance and execute it but the jar is running in Private DNS mode. I am not able to access the http and https urls from my local machine. I already enabled all traffic to access the api (in Security Group). Do I miss anything to get the api access over the internet? How can I run my api in public DNS mode?

Related

Static IP for internal communication in AWS for microservices

I have 7 Spring microservices with Eureka Server which I would like to deploy into AWS Elastic Beanstalk. Every time when I redeploy microservice I see that the url address is changed. Is it possible to use internal static IP for every AWS service?
I was also facing this problem with managing EB instances remotely, I have fixed this in two ways:
For myself I use eb ssh from EB CLI to remotely access instances. As the CLI gives you an option to select which instance you want to connect to if there are more than one. If your microservices are in a private subnet you need a bastion to connect to your instances remotely.
using AWS System manager / Session Manager
You can install a System manager agent on your elastic beanstalk environment using ebextensions. Using Systems managers; Session manager you can start a session towards your microservice and all your commands will be logged towards S3 (can be usefull for change management / complaincy)
As I want straight to these two options; I never fixed the issue where private IP's changed.

How to connect AWS ECS Service to database in EC2 instance?

I have a SQL Server database running on Windows Server EC2 instance. I also have Web API (ASP.NET Core WebAPI) deployed as a Service in ECS cluster (Fargate launch type).
What connection string should I use to access this database from my web API?
Right now I'm trying:
data source=NAME_OF_THE_EC2_INSTANCE;initial
catalog=DATABASE_NAME;User
Id=USER_NAME;Password=PASSWORD;MultipleActiveResultSets=True;App=EntityFramework;Connection Timeout=10;
But it doesn't work. The error returned suggests that the app doesn't even see the database at all.
It seems you'll need to use a NAT instance/Gateway
This will enable connectivity between your Fargate instance and EC2 instance where DB is installed.
Another source and also the official documentation
"...Container instances need external network access to communicate with the Amazon ECS service endpoint, so if your container instances are running in a private VPC, they need a network address translation (NAT) instance to provide this access. For more information, see NAT Instances in the Amazon VPC User Guide."

Running Get command on EC2 from Lambda

I am new to AWS environment.I have installed apache Atlas in EC2 instance and from Lambda I am trying to get metadata from glue data catalog and post it in apache atlas(apache atlas uses rest end-points) running on ec2.I am able to get the glue data catalog metadata in lambda function.
How can i access use curl/httpGet call from lambda function to access service running on port 21000 on localhost on my EC2 instance?
Update1 : Resolved by allowing all traffic for inbound on private IP for the EC2 instance in security group.
Update2 : Now I am able to access the rest URL(by its private IP) and glue catalog both within Lambda.What I did is I created a private and public subnet and put my EC2 instance and lambda on same private subnet with NAT configured on a public subnet.
Now my lambda is working but I am not able to ssh on my EC2 instance.Is there a way to get that working also?
"localhost" is relative to each computer. What is "localhost" on your EC2 server is different from what is "localhost" on AWS Lambda, etc. You need to stop trying to access "locahost" and use the server's IP address instead.
To access port 21000 on the EC2 server the Lambda function needs to be placed in the same VPC that the EC2 instance is in, and the EC2 server needs to be listening to external traffic on port 21000, not just localhost traffic. You would assign a security group to the Lambda function, and in the security group assigned to the EC2 server you would open port 21000 for traffic coming from the Lambda function's security group. Finally, the Lambda function would access the EC2 server by addressing it via the server's private IP.
I'm not familiar with Apache Atlas and whether it exposes it's own HTTP endpoints to external clients. What you need is a server running on EC2 for that.
EC2 server doesn't magically accept HTTP calls from external connections and route to the local resources you want (in this case, Atlas). Install Apache Server, nginx or any other server in your EC2 instance. Configure it properly and write some code that takes the data POSTed by your Lambda and submits to the local Apache Atlas API.
The following page contains some instructions in this direction. Search the web if you need more help, there are tons of tutorials for doing this already. https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Tutorials.WebServerDB.CreateWebServer.html

AWS EC2 Instance without private ip (windows)

I am starting new instances via a launch configuration where userdata is specified. This data only needs to download a configuration file from S3. The instance is launched with an IAM role that has full S3 rights.
I can confirm that the script does work, if I create the instances with public ip's everything is gravy. However if there is no public ip, it just hangs. I can use a jump box and remote into the box, the user script is there, if I run it, it just hangs.
I have no need for these machines (web servers) to have public ip's as they are behind an ELB and Route 53.
If your instances have no public-IP and no route to the public Internet you could consider using a VPC endpoint to reach S3:
https://aws.amazon.com/blogs/aws/new-vpc-endpoint-for-amazon-s3/

Amazon Ec2 instance access using elastic ip address

I installed jboss in my ec2 instance. My elastic ip address 52.16.53.218.
I deployed my retailproduct application. Server is started. Deployed successfully, but I can't access my application.
I tried below ways:
http://localhost:8080/retailcare
http://127.0.0.1:8080/retailcare
http://52.16.53.218:8080/retailcare
I can't access. Any help appreciated.
Accessing localhost stays totally within the Amazon EC2 instance, so it would not be impacted by Security Group.
If you are able to SSH/RDP to the actual server and accessing http://localhost:8080/retailcare does not work, then it is a problem with your application or JBoss configuration.