USTA Connect Portal Use: API Operation
Overview
This document explains how a partner can upload to or retrieve files from their assigned folder in an S3 bucket. The instructions use the AWS S3 API, but the same functionality can also be implemented in a Python project using the Boto3 S3 library.
Folder Creation
On request we will create a specific location for our partner and API keys to perform the operation and will be shared with concerned person from partner team.
Required information from USTA
S3 Access point: Access point arn.
Prefix: partner file location.
API keys: Access key and secret.
File Operations Using AWS CLI
List Object
aws s3api list-objects-v2 --bucket <ACCESS_POINT> --prefix <PREFIX> --profile partner-<partner_name>
Get Object
aws s3api get-object --bucket <ACCESS_POINT> --key <PREFIX>/ChocolateChipCookie.png C:\aaa\ChocolateChipCookie-GET.png --profile partner-<partner_name>
Put Object
aws s3api put-object --bucket <ACCESS_POINT> --key <ACCESS_POINT>/ChocolateChipCookie.png --body C:\aaa\ChocolateChipCookie.png --profile partner-<partner_name>
Creating named profiles
You can configure profiles by using aws configure with the --profile option, or by manually adding entries to the config and credentials files.
Credentials profile
The following example shows a credentials file with two profiles. The first [default] is used when you run a AWS CLI command with no profile. The second is used when you run a AWS CLI command with the --profile user1 parameter.
The credentials file uses a different naming format than the AWS CLI config file for named profiles. Do not use the word profile when creating an entry in the credentials file.
~/.aws/credentials (Linux & Mac) or %USERPROFILE%\.aws\credentials (Windows)
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
[user1]
aws_access_key_id=AKIAI44QH8DHBEXAMPLE
aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY
Config profile
Each profile can specify different credentials and can also specify different AWS Regions and output formats. When naming the profile in a config file, include the prefix word "profile".
The following example specifies Region and output information for the default and user1 profiles.
~/.aws/config (Linux & Mac) or %USERPROFILE%\.aws\config (Windows)
[default]
region=us-west-2
output=json
[profile user1]
region=us-east-1
output=text
Python program
Python code to upload and list objects from bucket
Upload file
import boto3
if __name__ == '__main__':
print('Starting upload')
session = boto3.Session(
aws_access_key_id='<ACCESS_KEY>',
aws_secret_access_key='<SECKET_KEY>',
)
file_path_on_local_drive = 'C:/Downloads/RETAIL-NAME-20251231.csv'
bucket_name = '<ACCESS_POINT>'
prefix = '<PREFIX>/RETAIL-NAME-20231231.csv'
s3 = session.resource('s3')
s3.meta.client.upload_file(Filename=file_path_on_local_drive, Bucket=bucket_name, Key=prefix)
print('done uploading')
List files
import boto3
if __name__ == '__main__':
print('Start Listing object')
session = boto3.Session(
aws_access_key_id='<ACCESS_KEY>',
aws_secret_access_key='<SECKET_KEY>',
)
bucket_name = '<ACCESS_POINT>'
prefix = '<PREFIX>'
conn = session.client('s3')
for key in conn.list_objects(Prefix=prefix, Bucket=bucket_name)['Contents']:
print(key['Key'])
print('done listing object')