Here are some of the main storage options in AWS:
- EBS (Elastic Block Store)
- EFS (Elastic File System)
- S3 (Simple Storage Service)
Microsoft .NET and Java Software Development
Here are some of the main storage options in AWS:
Yay, Friday night, personal learning time!
I'm starting to look into next steps of "how would I deploy new versions of my Spring Boot Application to ECS"?
Initial thoughts would be to do the following:
First, taking a look at what I have running now in my ECS Cluster:
I'm a firm believer that every technology professional has stumbling blocks, something that no matter how hard they try, it's just difficult to "make that knowledge stick".
For some, it's RegEx, for others it could be DNS configuration.
One of mine is around networking, subnets, and netmasks.
Unfortunately, understanding these concepts is essential to AWS Virtual Private Cloud (VPC) configuration.
Here's how I set up my VPC, Subnets, and, Route Tables, and Internet Gateways for my EC2 / ECS studies.
VPC: This is the starting point.
I created a new VPC with the name web-apps and an IPv4 CIDR block of: 10.0.0.0/24
/24 is the equivalent of a Netmask of 255.255.255.0
The way I've learned to think of CIDR blocks and Netmasks for IPv4 ... there are 4 Octets, and each Octet is 8 bits.
/24 means that there are 24 1-bits in the Netmask, taking up 3 of the Octets, hence 255.255.255.0.
The higher the number (up to 32, or all 4 Octets, the more restrictive).
The lower the number (down to 0, or none of the Octets, the less restrictive).
So 0.0.0.0/0 on something like an Ingress Rule means "let the world in".
Going back to my VPC, CIDR block of: 10.0.0.0/24
32 (all bits in an IPv4 Address) - 24 (from CIDR Block) = 8 (number of bits available for addresses in my VPC).
These days, containers and ECS/EKS seem to be all the rage. However, I wanted to make sure I could still install and run my application on an EC2 Instance.
I decided to create an EC2 Instance t2.micro) using the AMI for Amazon Linux 2.
Step 1: Installing Java 17 (Amazon Corretto)
after all the dependencies were downloaded, installed, and this completed, I verified:
[ec2-user@ip-10-0-0-72 ~]$ java -version
openjdk version "17.0.5" 2022-10-18 LTS
OpenJDK Runtime Environment Corretto-17.0.5.8.1 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.5.8.1 (build 17.0.5+8-LTS, mixed mode, sharing)
export JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto.x86_64
[Unit] Description=Java Spring Boot Demo App After=syslog.target [Service] WorkingDirectory=/opt/java-apps ExecStart=/bin/java -jar demo.jar SuccessExitStatus=143 User=java-user Group=java-group [Install] WantedBy=multi-user.target
Now that I have an ECR Image (built locally and pushed up from Docker Desktop) and an ECS Cluster Created, next step is to create a Task Definition.
I provided the Container Port of 8080 (same as the one I exposed in the Dockerfile of the Image).
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "iam:CreateRole", "iam:AttachRolePolicy" ], "Resource": "*" } ] }
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ecr:CreateRepository", "ecr:CompleteLayerUpload", "ecr:GetAuthorizationToken", "ecr:UploadLayerPart", "ecr:InitiateLayerUpload", "ecr:BatchCheckLayerAvailability", "ecr:PutImage" ], "Resource": "*" } ] }
C:\>aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ************.dkr.ecr.us-east-1.amazonaws.com Login Succeeded C:\>docker tag f94c25ad91cd1dabbb0dae012a0da3f50c23e050fdd1916d7bd81d5c9dbec2b9 ************.dkr.ecr.us-east-1.amazonaws.com/java-spring-cloud-demo:v0.0.1 C:\>docker push ************.dkr.ecr.us-east-1.amazonaws.com/java-spring-cloud-demo:v0.0.1 The push refers to repository [************.dkr.ecr.us-east-1.amazonaws.com/java-spring-cloud-demo] e971bfdd6e68: Pushed cb90fdeb280a: Pushed 15b10c92f3b2: Pushed e5e13b0c77cb: Pushed v0.0.1: digest: sha256:6bee10abc02d77bced7593744f31b4d373069042cb45ae4cf4a2648992b5265a size: 1161
Next step in my weekend AWS / Container / Spring Boot experimentation is to try and actually get my Docker Image pushed up to ECR.
It runs fine in my local Docker Desktop, but I want to get it running as a service in AWS ECS.
In following AWS best practices:
"We strongly recommend that you do not use the root user for your everyday tasks, even the administrative ones. Instead, adhere to the best practice of using the root user only to create your first IAM user. Then securely lock away the root user credentials and use them to perform only a few account and service management tasks. To view the tasks that require you to sign in as the root user, see AWS Tasks That Require Root User."
Source: https://docs.aws.amazon.com/IAM/latest/UserGuide/id.html?icmpid=docs_iam_console
I created a new IAM user called java-demo and Policy called ECR-PushImages that should allow this IAM user to push to any ECR Repository.
If I were working in an enterprise environment, I would restrict resources, but since this is home studies, I'm leaving it open.
C:\>aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin **********.dkr.ecr.us-east-1.amazonaws.com Login Succeeded
FROM amazoncorretto:17.0.5-alpine3.16 RUN addgroup -S spring && adduser -S java -G spring USER java:spring ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","/app.jar"]
I found this plugin recently and absolutely love it: git-commit-id-maven-plugin
It generates a properties file (can select format, I use properties instead of json) under target/classes directory.
Here is the setup I am using on my home demo project:
pl.project13.maven git-commit-id-plugin 4.9.10 initialize get-the-git-infos revision ${project.basedir}/.git git false true ${project.build.outputDirectory}/git.properties ^git.build.(time|version)$ ^git.build.user.name$ ^git.commit.id$ ^git.commit.id.abbrev$ properties false false -dirty
The best way to make use of this plugin is to run it without the includeOnlyProperties section and see all the git information it generates.
From there, figure out which properties you actually want, and add the includeOnlyProperties section and specify just those properties.
It's a lovely, foggy Saturday. Perfect time to start digging into AWS.
I figured I would try and get a demo/Hello World Spring Boot App running inside a Docker Container, push the Docker Image up to ECR and try and get it running in Amazon Fargate and blog my experience.
1. Amazon Corretto. I have a slightly-outdated version of Amazon's OpenJDK 17 running on my home Dev machine.
c:\>java -version openjdk version "17.0.1" 2021-10-19 LTS OpenJDK Runtime Environment Corretto-17.0.1.12.1 (build 17.0.1+12-LTS) OpenJDK 64-Bit Server VM Corretto-17.0.1.12.1 (build 17.0.1+12-LTS, mixed mode, sharing)
I guess I could run on this, but decided to get the latest. cURL command to get the latest AmazonCorretto JDK for Windows:
curl -LO https://corretto.aws/downloads/latest/amazon-corretto-17-x64-windows-jdk.zip
At home I run WSL2 on my Windows Dev machine. I have a MacBook Pro also and jump between the 2 of them for personal development.
(don't forget to run a checksum to make sure the file was not tampered with, this actually saved me once)
I then manually went to https://corretto.aws/downloads/latest_sha256/amazon-corretto-17-x64-windows-jdk.zip and verified that the SHA-256 checksum is the same:
a89555d3a482f67bfdb9fe07b906592e9763e047e435f811c34b72bebd4200b3
After unzipping and setting up JAVA_HOME and Windows Path:
c:\>java -version openjdk version "17.0.5" 2022-10-18 LTS OpenJDK Runtime Environment Corretto-17.0.5.8.1 (build 17.0.5+8-LTS) OpenJDK 64-Bit Server VM Corretto-17.0.5.8.1 (build 17.0.5+8-LTS, mixed mode, sharing)
2. Spring Initializr + IntelliJ
I bought a JetBrains All Products Pack earlier this week (previously had been using IntelliJ CE + VS Code for Java + Angular personal development).
IntelliJ Ultimate Edition has great support for Spring Initializr.
PS C:\work\spring-boot-aws\demo> ./mvnw package PS C:\work\spring-boot-aws\demo> java -jar .\target\demo-0.0.1-SNAPSHOT.jar
I've started learning ReactJS.
Reading through React JS Foundations.
I'm coming from years of Angular development, both professional and personally (TypeScript Angular, but AngularJS 1.x before that).
The toolchain ... Node.js, NPM, NPX, node_modules all are good commonalities across both frameworks.
However, React feels much "closer to the rails" than Angular. In the first Hello World example, I'm already going at the DOM by way of document.querySelector.