Step-by-Step Instructions for Programmatic Access to AWS Services using AWS CLI
Step 1: Install and Configure AWS CLI
- Install AWS CLI:
- Download and install the AWS CLI for your operating system from the official AWS CLI website.
- Open a terminal or command prompt:
- Launch a terminal (Linux/Mac) or command prompt (Windows).
- Configure AWS CLI:
-
Run the following command to configure the AWS CLI:
-
aws configure
- Provide the following information when prompted:
- AWS Access Key ID: Your access key ID.
- AWS Secret Access Key: Your secret access key.
- Default region name: The AWS region you want to use (e.g., us-east-1).
- Default output format (optional): The output format (e.g., json).
-
-
Step 2: List Objects in an S3 Bucket
- Run the command below to view a list of the objects/files that are present in the specified S3 bucket:
- aws s3 ls s3://your-bucket-name
- In the case of the suppression file, the bucket name is 'deep-sync-30-day-suppression'. To view the contents of this bucket run:
- aws s3 ls s3://deep-sync-30-day-suppression
Step 3: Download a File from an S3 Bucket
- Determine the S3 URL and the directory to which you'd like to download the file.
- Identify the S3 URL of the file you want to download (e.g., s3://my-bucket/documents/example.txt).
- Decide the directory where you want to save the file (e.g., /home/user/downloads).
- Run the command below to download the file:
- aws s3 cp s3://bucket-name/path/to/file /path/to/local/directory
- Note: When running this command, you will replace s3://bucket-name/path/to/file with the S3 object's URL and /path/to/local/directory with the path to your desired directory from Step 1.
- aws s3 cp s3://bucket-name/path/to/file /path/to/local/directory
Example Scenario:
Suppose you want to download a file named example.txt from the S3 bucket my-bucket located in the folder documents to your local /home/user/downloads directory.
Run the command below to download the file example.txt from the specified S3 bucket to the /home/user/downloads directory on your local machine.
aws s3 cp s3://my-bucket/documents/example.txt /home/user/downloads/
For more more information on accessing files via S3 please visit Amazon's AWS Documentation.