Showing posts with label Amazon Web Services. Show all posts
Showing posts with label Amazon Web Services. Show all posts

Monday, 20 January 2025

How to Use AWS S3 Select to Query Data in S3 | What is AWS S3 Select? A Beginner's Guide

🚀 Level Up Your Tech Skills!

Subscribe to Ram N Java for simplified AWS tutorials, Java source code, and expert tips!

SUBSCRIBE TO CHANNEL

What is AWS S3 Select? A Beginner's Guide

Imagine you have a massive storage bucket filled with huge files (like spreadsheets or logs) in Amazon S3. Usually, if you need just one specific piece of information, you have to download the entire file first. This wastes time, bandwidth, and money.

AWS S3 Select changes that. It acts like a "Smart Filter" that lets you pull out only the specific rows of data you need directly from S3.

The Librarian Analogy

Think of AWS S3 Select as asking a Librarian to find and photocopy just two specific pages from a 1,000-page book. Instead of carrying the whole heavy book home, you only get the pages you actually need!

How It Works in 3 Simple Steps

  1. Store: Upload your CSV or JSON files to an S3 bucket.
  2. Query: Use a simple SQL-like command (e.g., "Give me rows where City = 'New York'").
  3. Receive: S3 Select scans the file and sends back only those specific rows.

Why Use It?

  • Saves Money: You pay less for data transfer because you're moving less data.
  • Faster Performance: Your applications don't have to process giant files.
  • Easy SQL: If you know basic SQL, you can use S3 Select immediately.

Important Update: New Accounts

Note: AWS has limited S3 Select for new customers. If your AWS account or bucket was created after July 25, 2024, you might see an error saying "The specified method is not allowed." Existing users can still use it as usual!

Want the PowerPoint Presentation or Java Source Code shown in the video? Check the links in the YouTube video description!

Friday, 8 November 2024

Amazon SQS Java: Send and Receive Product Objects | Amazon SQS: Sending and Receiving Custom Objects

🚀 Master AWS Development with Java!

Subscribe to Ram N Java for more hands-on tutorials on AWS SDK and Java integration.

SUBSCRIBE TO THE CHANNEL

Introduction

Amazon Simple Queue Service (SQS) is a fundamental tool for building decoupled, distributed systems. While SQS natively handles strings, most real-world applications need to exchange complex data. In this tutorial, we demonstrate how to use the AWS SDK for Java and Jackson to send and receive custom Product objects by serializing them into JSON.

Step 1: Maven Dependencies

To follow along, ensure your pom.xml includes the AWS SDK for SQS and the Jackson library for JSON processing:

<!-- AWS SDK for SQS -->
<dependency>
    <groupId>software.amazon.awssdk</groupId>
    <artifactId>sqs</artifactId>
    <version>2.x.x</version>
</dependency>

<!-- Jackson for JSON -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
</dependency>

Step 2: Defining the Product Class

Create a simple POJO to represent your data. This class should have a default constructor and standard getters/setters for Jackson to work correctly.

public class Product {
    private int id;
    private String name;
    private double price;
    // Getters and Setters
}

Step 3: The Producer (Sending Objects)

The producer converts the Java object to a JSON string using ObjectMapper and sends it to the SQS queue using the SendMessageRequest.

ObjectMapper mapper = new ObjectMapper();
String productJson = mapper.writeValueAsString(new Product(1, "iPhone 16 Pro Max", 125000));

SendMessageRequest sendMsgRequest = SendMessageRequest.builder()
    .queueUrl(queueUrl)
    .messageBody(productJson)
    .build();
sqsClient.sendMessage(sendMsgRequest);

Step 4: The Consumer (Receiving Objects)

The consumer receives the message, extracts the JSON body, and deserializes it back into a Product object. Don't forget to delete the message after successful processing!

ReceiveMessageResponse response = sqsClient.receiveMessage(receiveRequest);
for (Message message : response.messages()) {
    Product product = mapper.readValue(message.body(), Product.class);
    System.out.println("Processing: " + product.getName());
    
    // Delete message from queue
    DeleteMessageRequest deleteRequest = DeleteMessageRequest.builder()
        .queueUrl(queueUrl)
        .receiptHandle(message.receiptHandle())
        .build();
    sqsClient.deleteMessage(deleteRequest);
}

Conclusion

By combining the AWS SDK with Jackson, you can easily pass complex data structures through Amazon SQS. This pattern is essential for microservices architectures where different components need to exchange typed data asynchronously. Happy coding!

Thursday, 7 November 2024

Java Integration with Amazon SQS: Sending and Receiving Messages | Amazon SQS Messaging with Java

🚀 Level Up Your AWS Skills!

Subscribe to Ram N Java for more hands-on AWS SDK and Java tutorials.

SUBSCRIBE ON YOUTUBE

Introduction

Integrating Amazon Simple Queue Service (SQS) with Java is a core skill for building scalable, decoupled applications. In this guide, we'll walk through setting up a Maven project, configuring credentials, and writing the code for both a Producer and a Consumer using the AWS SDK for Java.

Step 1: Maven Project Setup

First, create a new Maven project and add the AWS SDK for SQS dependency to your pom.xml file. This allows your application to communicate with Amazon's messaging infrastructure.

<dependency>
    <groupId>software.amazon.awssdk</groupId>
    <artifactId>sqs</artifactId>
    <version>2.x.x</version>
</dependency>

Step 2: Configure AWS Credentials

Ensure your local machine is configured with valid AWS credentials. You should have a .aws folder containing:

  • credentials file: Includes your aws_access_key_id and aws_secret_access_key.
  • config file: Specifies your preferred AWS region.

Step 3: Creating the Producer

The Producer's job is to initialize the SqsClient, create a queue (if it doesn't exist), and send messages. Here is the logic:

// Initialize client and send message
SqsClient sqsClient = SqsClient.builder().build();
SendMessageRequest sendMsgRequest = SendMessageRequest.builder()
    .queueUrl(queueUrl)
    .messageBody("Samsung Galaxy")
    .build();
sqsClient.sendMessage(sendMsgRequest);

Step 4: Creating the Consumer

The Consumer polls the queue for messages, processes them, and then explicitly deletes them to prevent reprocessing.

// Receive and delete messages
ReceiveMessageResponse response = sqsClient.receiveMessage(receiveRequest);
for (Message message : response.messages()) {
    System.out.println("Processing: " + message.body());
    // Delete message after processing
    sqsClient.deleteMessage(deleteRequest);
}

Conclusion

By leveraging the AWS SDK for Java, you can implement robust messaging patterns with very little boilerplate code. This setup ensures that your services can exchange data reliably and asynchronously in the cloud. Happy coding!

Tuesday, 3 September 2024

How to Set Up and Use Amazon AWS CLI on Windows/Mac/Linux | AWS CLI Installation and Basic Usage

Ready to Level Up Your Cloud Skills? ☁️

Don't miss out on more AWS and Java tutorials. Join our growing community today!

👉 SUBSCRIBE TO RAM N JAVA

Introduction

The AWS Command Line Interface (CLI) is a unified tool that allows you to manage your AWS services from the terminal. Instead of clicking through the AWS Management Console, you can run powerful commands to automate your workflows and manage resources like S3, EC2, and SQS efficiently.

Step 1: Installing AWS CLI

Depending on your operating system, follow the steps below:

Windows

  • Download the AWS CLI MSI Installer from the official AWS website.
  • Run the installer and follow the "Next" prompts until finished.

macOS

brew install awscli

Linux

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Step 2: Configuring Your Credentials

Once installed, you need to link the CLI to your AWS account. First, create an IAM User in the AWS Console to get your Access Key and Secret Key. Then, run:

aws configure

Provide the following when prompted:

  • AWS Access Key ID
  • AWS Secret Access Key
  • Default region name (e.g., us-east-1)
  • Default output format (e.g., json)

Step 3: Essential AWS Commands

Amazon S3 (Storage)

List all your buckets:

aws s3 ls

Create a new bucket:

aws s3 mb s3://my-unique-bucket-name

Amazon EC2 (Servers)

List your running instances:

aws ec2 describe-instances

Amazon SQS (Queues)

Create a simple message queue:

aws sqs create-queue --queue-name MyQueue

Conclusion

Mastering the AWS CLI is a game-changer for cloud engineers. It allows for faster management, easy scripting, and powerful automation. Start practicing these commands today to streamline your cloud operations!

Monday, 19 August 2024

What is Amazon SQS Redrive Allow Policy? | Amazon SQS Tutorial

🚀 Master the AWS Ecosystem!

Join the Ram N Java community for more expert cloud-native Java tutorials.

SUBSCRIBE ON YOUTUBE

Introduction

Amazon Simple Queue Service (SQS) is a powerful tool for building decoupled systems, but as your architecture grows, so does the complexity of managing failed messages. The Redrive Allow Policy is a critical feature that gives you granular control over which queues can use a specific Dead Letter Queue (DLQ).

What is a Dead Letter Queue (DLQ)?

A DLQ is a specialized queue that stores messages that cannot be processed successfully after a specific number of attempts. This helps developers isolate problematic messages for further analysis without blocking the main message flow.

The Role of the Redrive Allow Policy

Think of the Redrive Allow Policy as a "guest list" for your Dead Letter Queue. By applying this policy to your DLQ, you specify exactly which primary queues are authorized to move their unprocessed messages there. This prevents unauthorized queues from filling up your error logs with irrelevant data.

Example Scenario

Imagine you have four different services: Order, Payment, Notification, and User. If you want only the first three to share a single error queue, you can define a policy on that DLQ to explicitly allow those specific ARNs while blocking others.

Key Benefits

  • Enhanced Security: Ensures only trusted queues interact with your DLQ.
  • Better Organization: Keeps your error-handling systems focused and clean.
  • Simplified Management: Control the entire message lifecycle from a central policy.

Conclusion

Implementing a Redrive Allow Policy is a best practice for any serious AWS architect. It adds a necessary layer of security and organization to your messaging infrastructure. Watch the full video above to see how to configure these settings directly in the AWS Console!

Friday, 6 May 2022

How to Connect to an EC2 instance on AWS using WinSCP? | SpringBoot-Deploying to AWS EC2 Instance

🚀 Master AWS & Java Today!

Subscribe to Ram N Java for more easy-to-follow cloud deployment tutorials.

SUBSCRIBE ON YOUTUBE

Introduction

WinSCP is a popular, free SFTP and FTP client for Windows. It provides a powerful graphical interface for transferring files between your local computer and a remote server, such as an Amazon EC2 instance. In this guide, we'll walk through installing WinSCP and configuring it to securely access your AWS instance.

Step 1: Download and Install WinSCP

Visit the official WinSCP website and download the installer. Follow the setup instructions. During installation, if you are asked to import sessions from PuTTY, you can choose "No" to start with a fresh configuration.

Step 2: Get Your EC2 Connection Details

Log in to your AWS Management Console and navigate to the EC2 Dashboard. Select your running instance to find the following information:

  • Public IPv4 Address: (or Public DNS name) to be used as the Host Name.
  • User Name: Typically ec2-user for Amazon Linux or ubuntu for Ubuntu instances.

Step 3: Configure Authentication (PPK File)

WinSCP uses the SSH protocol, which requires your private key for authentication. If you have a .pem file from AWS, WinSCP can automatically convert it to a .ppk file:

  1. Open WinSCP and click on Advanced.
  2. Under the SSH section, click on Authentication.
  3. Browse and select your .pem file. WinSCP will offer to convert it; click "OK" and save the new .ppk file.

Step 4: Login and Transfer Files

With the Host Name, User Name, and Key file configured, click Login. Once connected, you will see your local files on the left and your EC2 server files on the right. You can now drag and drop files to transfer them instantly!

Conclusion

You have successfully connected to your AWS EC2 instance using WinSCP. This setup is essential for deploying applications, managing server configurations, and handling logs. Keep practicing and explore the advanced features of WinSCP to speed up your workflow!

Tutorials