Closed RammusXu closed 8 years ago
Command aws s3 ls s3://xxxxxxxxx.com.tw
A client error (PermanentRedirect) occurred when calling the ListObjects operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint: cdn.gundam.com.tw.s3.amazonaws.com You can fix this issue by explicitly providing the correct region location using the --region argument, the AWS_DEFAULT_REGION environment variable, or the region variable in the AWS CLI configuration file. You can get the bucket's location by running "aws s3api get-bucket-location --bucket BUCKET".
use aws s3 ls s3://xxxxxxxxx.com.tw --region REJION_NAME
example: aws s3 ls s3://xxxxxxxxx.com.tw --region us-east-1
http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
使用Provider Chain
AmazonS3 s3Client = new AmazonS3Client();
AmazonS3 s3Client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain());
使用指定的方法
AmazonS3 s3Client = new AmazonS3Client(new EnvironmentVariableCredentialsProvider());
在java code寫入
BasicAWSCredentials awsCreds = new BasicAWSCredentials({access_key_id}, {secret_access_key})
AmazonS3 s3Client = new AmazonS3Client(awsCreds);
AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
. The AWS SDK for Java uses the EnvironmentVariableCredentialsProvider
class to load these credentials.aws.accessKeyId
and aws.secretKey
. The AWS SDK for Java uses the SystemPropertiesCredentialsProvider
to load these credentials.~/.aws/credentials
(this location may vary per platform), this credentials file is shared by many of the AWS SDKs and by the AWS CLI. The AWS SDK for Java uses the ProfileCredentialsProvider
to load these credentials.InstanceProfileCredentialsProvider
to load these credentials.http://docs.aws.amazon.com/java-sdk/latest/developer-guide/setup-credentials.html
~/.aws/credentials
on Linux, OS X or unixC:\Users\USERNAME\.aws\credentials
on Windows[default]
aws_access_key_id={YOUR_ACCESS_KEY_ID}
aws_secret_access_key={YOUR_SECRET_ACCESS_KEY}
more info: Configuring the AWS Command Line Interface
On Linux, OS X or unix, use export:
export AWS_CREDENTIAL_PROFILES_FILE=path/to/credentials_file
On Windows, use set:
set AWS_CREDENTIAL_PROFILES_FILE=path/to/credentials_file
To set these variables on Linux, OS X or unix, use export:
export AWS_ACCESS_KEY_ID=your_access_key_id
export AWS_SECRET_ACCESS_KEY=your_secret_access_key
To set these variables on Windows, use set:
set AWS_ACCESS_KEY_ID=your_access_key_id
set AWS_SECRET_ACCESS_KEY=your_secret_access_key
unset AWS_CREDENTIAL_PROFILES_FILE
import boto3
# Let's use Amazon S3
s3 = boto3.resource('s3')
# Print out bucket names
for bucket in s3.buckets.all():
print(bucket.name)
bucketName = 'my_domain.com.tw'
bucket = s3.Bucket(bucketName)
# 印出bucket下所有物件
for obj in bucket.objects.all():
print(obj.key)
# 指定一個物件,取出後存成test
objName = 'bucket_obj/a_obj'
s3.Object(bucketName,objName).download_file('test')
注意事項
步驟
Reference