AWS is the dominant cloud platform and knowledge of its core services is now a baseline requirement for senior Java developers. This guide covers the AWS services most relevant to Java backend developers, with interview-ready answers and Spring Boot integration examples.
1. What is EC2 and when would you use it?
EC2 (Elastic Compute Cloud) provides virtual machines (instances) in the cloud. You choose the instance type (CPU, memory), OS, and configure networking and storage. EC2 gives full control over the environment.
When to use EC2: Long-running server applications, databases (self-managed), applications needing custom OS configuration, Spring Boot apps that aren't containerized. For containerized apps, prefer ECS or EKS.
Key concepts: AMI (Amazon Machine Image — OS + software template), Security Groups (firewall rules), Elastic IP (static public IP), EBS volumes (persistent block storage), Auto Scaling Groups (scale up/down based on metrics).
2. What is S3 and what are its use cases?
S3 (Simple Storage Service) is object storage — store and retrieve any amount of data as objects (files) in buckets. Virtually unlimited capacity, 99.999999999% durability.
Java/Spring Boot use cases:
- Storing user-uploaded files (profile images, documents, videos)
- Static website hosting (HTML, CSS, JS)
- Application backup and restore
- Data lake for analytics
- Serving large static assets via CloudFront CDN
// Spring Boot with AWS SDK v2
@Service
public class S3FileService {
private final S3Client s3Client;
private final String bucketName;
public String uploadFile(String key, InputStream content, long size) {
s3Client.putObject(PutObjectRequest.builder()
.bucket(bucketName).key(key)
.contentType("image/jpeg").build(),
RequestBody.fromInputStream(content, size));
return "https://" + bucketName + ".s3.amazonaws.com/" + key;
}
public InputStream downloadFile(String key) {
return s3Client.getObject(GetObjectRequest.builder()
.bucket(bucketName).key(key).build());
}
public URL generatePresignedUrl(String key, Duration duration) {
S3Presigner presigner = S3Presigner.create();
return presigner.presignGetObject(b -> b
.signatureDuration(duration)
.getObjectRequest(r -> r.bucket(bucketName).key(key)));
}
}
3. What is the difference between RDS and DynamoDB?
| RDS | DynamoDB |
|---|---|
| Managed relational DB (MySQL, PostgreSQL, Aurora) | Managed NoSQL key-value + document DB |
| ACID transactions, complex joins, SQL | Single-digit millisecond latency, massive scale |
| Vertical scaling (larger instance) | Horizontal scaling (partitioned automatically) |
| Best for transactional, relational data | Best for high-volume, key-lookup patterns |
| Hibernate/JPA works natively | Use DynamoDBMapper or Spring Data DynamoDB |
Use RDS when: You need complex queries, joins, strong consistency, or existing SQL application. Use DynamoDB when: You need millions of requests/second, global tables, or flexible schema at internet scale (session store, IoT telemetry, leaderboards).
4. What is AWS Lambda and when should you use it?
Lambda is serverless compute — run code without provisioning servers. You upload a function (jar, zip); AWS runs it in response to triggers (HTTP via API Gateway, S3 events, SQS messages, scheduled events). You pay only for execution time (no idle cost).
// Spring Boot Lambda with AWS Lambda Adapter (Spring Cloud Function)
@SpringBootApplication
public class JiQuestLambdaApp {
@Bean
public Function<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> handler() {
return request -> {
String body = request.getBody();
// process...
return APIGatewayProxyResponseEvent.builder()
.statusCode(200)
.body("{\"status\":\"ok\"}")
.build();
};
}
}
Limitations: Cold start latency (100ms–5s for JVM), 15-minute max execution time, 10GB max memory. For always-on, low-latency Java APIs, ECS/EKS with containers is better.
5. What is the difference between SQS and SNS?
SQS (Simple Queue Service): Message queue. Messages are stored until a consumer pulls and processes them. One consumer per message (by default). Use for decoupling services and background job processing.
SNS (Simple Notification Service): Pub/Sub. A publisher sends a message to a Topic; SNS fans it out to all subscribers simultaneously (SQS queues, Lambda functions, email, HTTP endpoints). One message → multiple consumers.
// SQS with Spring Cloud AWS
@SqsListener("order-processing-queue")
public void processOrder(OrderMessage order) {
orderService.process(order); // only one consumer processes each message
}
// SNS publish (one event → many consumers)
@Autowired private SnsTemplate snsTemplate;
public void publishOrderCreated(Order order) {
snsTemplate.sendNotification("order-created-topic",
objectMapper.writeValueAsString(order), "order-created");
// SNS fans out to: SQS queues for billing, shipping, analytics
}
6. What is IAM and how does it work?
IAM (Identity and Access Management) controls who can do what in your AWS account. Everything in AWS is denied by default — access is granted by attaching IAM policies.
Key concepts:
- IAM User: A permanent identity for humans (developers, CI/CD systems). Has access keys or console password.
- IAM Role: Temporary identity assumed by AWS services (EC2, Lambda, ECS) or federated users. Best practice — use roles for services, not access keys.
- IAM Policy: JSON document specifying allowed/denied actions on resources. Attached to users, groups, or roles.
// Example IAM policy: allow a Lambda to read from S3 and write to DynamoDB
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::jiquest-files/*"
},
{
"Effect": "Allow",
"Action": ["dynamodb:PutItem", "dynamodb:GetItem"],
"Resource": "arn:aws:dynamodb:ap-south-1:*:table/Sessions"
}
]
}
7. What is ECS vs EKS?
ECS (Elastic Container Service): AWS-native container orchestration. Simpler than Kubernetes — less operational overhead. Two launch modes: EC2 (you manage instances) and Fargate (serverless — no instances to manage). Good choice if you are already in the AWS ecosystem and don't need Kubernetes-specific features.
EKS (Elastic Kubernetes Service): Managed Kubernetes. Use if your team already knows Kubernetes, you need Kubernetes-specific tools (Helm, Kustomize, Argo CD), or you need cloud portability (can migrate to GKE or AKS). More complex and expensive than ECS.
8. What is ElastiCache and how is it used with Spring Boot?
ElastiCache is a managed in-memory caching service. It supports Redis and Memcached. Use it to cache database query results, session storage, rate limiting, and pub/sub messaging.
# application.yml
spring:
cache:
type: redis
data:
redis:
host: your-cluster.cache.amazonaws.com # ElastiCache endpoint
port: 6379
ssl.enabled: true # ElastiCache in-transit encryption
@Service
public class PostService {
@Cacheable(value = "posts", key = "#id")
public Post findById(Long id) {
return postRepository.findById(id).orElseThrow(); // hit DB only on cache miss
}
@CacheEvict(value = "posts", key = "#post.id")
public Post update(Post post) {
return postRepository.save(post); // evict cache on update
}
}
9. What is CloudWatch and why is it important?
CloudWatch is AWS's observability service — logs, metrics, alarms, and dashboards. Every AWS service publishes metrics to CloudWatch automatically (EC2 CPU, RDS connections, Lambda duration/errors).
Key features for Java developers:
- CloudWatch Logs: Aggregate application logs from ECS/EC2/Lambda. Search with Logs Insights (SQL-like query language).
- CloudWatch Metrics + Alarms: Alert when CPU > 80%, error rate > 1%, latency > 1s.
- CloudWatch Dashboards: Visual overview of your system health.
# Spring Boot: publish custom metrics to CloudWatch
management:
metrics:
export:
cloudwatch:
namespace: JiQuest/API
enabled: true
endpoints:
web:
exposure:
include: health, metrics, prometheus
10. How do you deploy a Spring Boot application to AWS?
Option 1 — Elastic Beanstalk (simplest): Upload your JAR; Beanstalk handles EC2, load balancer, auto-scaling, and deployment. Best for getting started quickly.
Option 2 — ECS with Fargate (recommended for production):
# Step 1: Build Docker image
docker build -t jiquest-api:latest .
# Step 2: Push to ECR (Elastic Container Registry)
aws ecr get-login-password | docker login --username AWS --password-stdin ACCOUNT.dkr.ecr.REGION.amazonaws.com
docker tag jiquest-api:latest ACCOUNT.dkr.ecr.REGION.amazonaws.com/jiquest-api:latest
docker push ACCOUNT.dkr.ecr.REGION.amazonaws.com/jiquest-api:latest
# Step 3: Update ECS service to use new image (rolling update)
aws ecs update-service --cluster jiquest-cluster --service jiquest-api --force-new-deployment
Option 3 — EKS (for teams already using Kubernetes): Build image, push to ECR, update Kubernetes Deployment manifest with new image tag, apply with kubectl or ArgoCD.
Conclusion
AWS knowledge is increasingly expected from senior Java developers — not just DevOps engineers. Focus on: S3 for file storage, RDS for relational data, SQS/SNS for async messaging, Lambda for event-driven functions, ECS/EKS for container deployment, ElastiCache for caching, IAM for security, and CloudWatch for observability. These are the services you will use daily in a Java microservices architecture on AWS.
Post a Comment
Add