This application provides a command-line interface for interacting with Amazon S3 (Simple Storage Service). You can perform various operations such as connecting to a bucket, listing objects, downloading files, and uploading files.
Before running the application, ensure you have the following:
- Java Development Kit (JDK) installed on your machine (version 8 or higher).
- Maven installed for building the project. You can check if Maven is installed by running
mvn -vin your terminal. - An AWS account with access to S3.
To package the application, follow these steps:
- Open a Terminal: Navigate to the root directory of your project where the
pom.xmlfile is located. For example:cd C:\Data\Projects\alfshare-aws-s3-services
- Build the Application: Run the following command to clean and package the application:
mvn clean package
clean: This command removes any previously compiled files and directories.package: This command compiles the source code, runs tests, and packages the application into a JAR file.
- Locate the Packaged JAR: After the build process completes successfully, you will find the packaged JAR file in the
targetdirectory. The JAR file will be named according to the<artifactId> and <version>specified in yourpom.xml. For example:target/s3client-0.0.1.jar
To run the packaged application, use the following command format:
java -jar target/s3client-0.0.1.jar <configFilePath> <operation> [<key> <filePath>]
The application requires a properties file that contains the necessary AWS credentials and configuration. Below is the format for the properties file:
aws.s3.region=my-region
aws.s3.bucketName=my-bucket
aws.s3.accessKey=YOUR_ACCESS_KEY
aws.s3.secretKey=YOUR_SECRET_KEYaws.s3.region=us-west-2
aws.s3.bucketName=my-example-bucket
aws.s3.accessKey=AKIAEXAMPLE
aws.s3.secretKey=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYTo run the application, use the following command format:
java -jar s3client-<versionNumber>.jar <configFilePath> <operation> [<key> <filePath>]The following operations are supported:
- connect: Check access to the specified S3 bucket.
java -jar s3client-0.0.1.jar ./application.properties connect- list: List objects in the specified S3 bucket. Optionally, you can provide a path to filter the results.
java -jar s3client-0.0.1.jar ./application.properties list
java -jar s3client-0.0.1.jar ./application.properties list Software- download: Download a file from the S3 bucket to a specified local path.
java -jar s3client-0.0.1.jar ./application.properties download <key> <filePath>
- upload: Upload a file from a specified local path to the S3 bucket.
java -jar s3client-0.0.1.jar ./application.properties upload <key> <filePath>To connect to the S3 bucket:
java -jar s3client-0.0.1.jar ./application.properties connectTo list all objects in the bucket:
java -jar s3client-0.0.1.jar ./application.properties listTo download a file from the S3 bucket:
java -jar s3client-0.0.1.jar ./application.properties download my-file.txt /local/path/to/save/my-file.txt
To upload a file to the bucket:
java -jar s3client-0.0.1.jar ./application.properties upload my-file.txt /local/path/to/my-file.txt
- Ensure that the AWS credentials provided in the properties file (application.properties) have the necessary permissions to perform the specified operations on the S3 bucket.
- Replace
<versionNumber>with the actual version of your application. - Replace
<configFilePath>, <operation>, <key> and <filePath>with the appropriate values for your use case. - If you encounter any issues during the build process, check the console output for error messages and resolve them accordingly.
For further reference, please consider the following sections: