28
loading...
This website collects cookies to deliver better user experience
.pem
file. In the EC2 AWS console, you need the Public IPv4 address of your instance which is located at the right top corner of the Details page.$ ssh -i EC2Blog.pem [email protected]
The authenticity of host '3.66.155.101 (3.66.155.101)' can't be established.
ECDSA key fingerprint is SHA256:/5EorRulTwyFKUJLfTvNPmUlHS9Mt1eTffPD4+9tcwU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '3.66.155.101' (ECDSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0664 for 'EC2Blog.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "EC2Blog.pem": bad permissions
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
.pem
file. Let’s check the file permissions.$ ll EC2Blog.pem
-rw-rw-r-- EC2Blog.pem
$ chmod 400 EC2Blog.pem
$ ll EC2Blog.pem
-r-------- EC2Blog.pem
$ ssh -i EC2Blog.pem [email protected]
__| __|_ )
_| ( / Amazon Linux 2 AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-2/
[ec2-user@ip-172-31-44-246 ~]$
{
"ip_prefix": "3.120.181.40/29",
"region": "eu-central-1",
"service": "EC2_INSTANCE_CONNECT",
"network_border_group": "eu-central-1"
}
$ sudo yum install java-11-amazon-corretto-headless
$ java --version
openjdk 11.0.11 2021-04-20 LTS
OpenJDK Runtime Environment Corretto-11.0.11.9.1 (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.11.9.1 (build 11.0.11+9-LTS, mixed mode)
sudo
before the command. Also, add the argument -y
to the yum
command, otherwise the installation will fail because the user will be prompted to continue the installation.cloud-init-output.log
. This will give you more information about any errors occurred during startup.$ sudo cat /var/log/cloud-init-output.log
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
String message = "Hello AWS!";
try {
InetAddress ip = InetAddress.getLocalHost();
message += " From host: " + ip;
} catch (UnknownHostException e) {
e.printStackTrace();
}
return message;
}
}
$ mvn clean verify
$ java -jar MyAWSPlanet-0.0.1-SNAPSHOT.jar
$ curl http://localhost:8080/hello
Hello AWS! From host: <computer name>/127.0.1.1
$ scp -i EC2Blog.pem MyAWSPlanet-0.0.1-SNAPSHOT.jar [email protected]:
$ curl http://18.194.164.14:8080/hello
Hello AWS! From host: ip-172-31-36-30.eu-central-1.compute.internal/172.31.36.30