AWS upload - bucket not found - c#

I have this in app.config:
<appSettings>
<add key="AWSProfileName" value="myName"/>
<add key="AWSRegion" value="eu-west-1" />
</appSettings>
Then I try to run this:
using Amazon.S3;
using Amazon.S3.Model;
namespace createCSV
{
class S3
{
public void uploadObject()
{
//IAmazonS3 client;
string AwsAccessKey = "xxxxxxxxxxxxx";
string AwsSecretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
IAmazonS3 client = new AmazonS3Client(AwsAccessKey,AwsSecretKey);
PutObjectRequest request = new PutObjectRequest()
{
BucketName = #"http://s3-eu-west-1.amazonaws.com/bucketName/",
Key = #"test/blah.txt",
FilePath = #"P:\data_analysis\foo\blah.txt"
};
PutObjectResponse response2 = client.PutObject(request); //<<exception here
}
}
}
I get an exception on the line marked saying:
Output>>
Cannot find or open the PDB file. Exception thrown:
'Amazon.S3.AmazonS3Exception' in AWSSDK.dll
AmazonS3exception was unhandled:
An unhandled exception of type 'Amazon.S3.AmazonS3Exception' occurred
in AWSSDK.dll
Additional information: The specified bucket does not exist
I've tried lots of different configurations for the line BucketName = #"http://s3-eu-west-1.amazonaws.com/bucketName/" with still the same exception - can anyone help?

I think,You forgot insert BucketName property in the PutObjectRequest.
see the example below to upload a file to AmazonS3.
string secretKey = "your secret key";
string accessKey = "your access key";
AmazonS3Client client = new AmazonS3Client(secretKey, accessKey, RegionEndpoint.EUWest1);// choose your region endpoin for this example I am usgin eu-west-1
PutObjectRequest uploadObjectRe = new PutObjectRequest()
{
BucketName = "qabucketireland",//your bucket name not full URL
Key = "test/blah.txt",
FilePath = #"c:\documents\script.txt"
};
client.PutObject(uploadObjectRe);
Another way to upload a file Could be using TransferUtility class see the example below:
string secretKey = "your secret key";
string accessKey = "your access Key";
AmazonS3Client client = new AmazonS3Client(secretKey, accessKey, RegionEndpoint.EUWest1);
TransferUtility transfer = new TransferUtility(client);
transfer.Upload(#"c:\documents\script - Copy.txt", "qabucketireland", #"test/blah2.txt");
Also You could read this "How to upload a file to amazon S3 super easy using c#"

The BucketName parameter to PutObjectRequest should be the name of the bucket (e.g. bucketName) rather than the fully qualified endpoint (e.g. http://s3-eu-west-1.amazonaws.com/bucketName/). You can find more info about the SDK here.

Related

The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint

Hi I found this error
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint
while run following code,
AmazonS3Config S3Config = new AmazonS3Config()
{
ServiceURL = "s3.amazonaws.com",
ForcePathStyle = true,
RegionEndpoint = RegionEndpoint.USEast1,
SignatureVersion = "v4"
};
// Set to a bucket you create
// Create S3 service client.
using (IAmazonS3 s3Client = new AmazonS3Client(kAWSAccessKeyId, kAWSSecretAccessKey, S3Config))
{
// Setup request for putting an object in S3.
PutObjectRequest request = new PutObjectRequest
{
BucketName = kBucketName,
Key = "Contents/SampleData",
ContentBody = "Sample Content"
};
// Make service call and get back the response.
PutObjectResponse response = s3Client.PutObject(request);
}
I have changed all region but in every region it showing same error

Amazon S3 Unable to find credentials in C#

I'm trying to upload an image file to aws s3 storage and get back that image URL. I'm using secret key and access key to create credentials. But when the program runs it it says
"Unable to find credentials" .
Here is my code which i used.
public string sendMyFileToS3(string from,string to, string bucketName, string fileName)
{
BasicAWSCredentials awsCreds = new BasicAWSCredentials(bucketName, fileName);
AmazonS3Client client = new AmazonS3Client(awsCreds);
TransferUtility utility = new TransferUtility(client);
TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
request.BucketName = bucketName;
request.Key = fileName;
request.FilePath = from;
utility.Upload(request);
string urlString = "";
GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest
{
BucketName = bucketName,
Key = fileName,
Expires = DateTime.Now.AddYears(2)
};
urlString = client.GetPreSignedURL(request1);
Console.WriteLine(urlString);
File.Move(from, to);
return urlString ;
}
In order to create an S3 Client you need to provide your credentials, the region and endpoint:
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "s3.amazonaws.com";
config.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("us-east-1");
client = new AmazonS3Client(credentials, config);
The possible regions are listed here, and depend on where you created your bucket being us-east-1 the default value.
While the possible endpoints are this three:
s3.amazonaws.com
s3-accelerate.amazonaws.com
s3-accelerate.dualstack.amazonaws.com
The first one being the standard one since the others need you to configure your bucket like it's explained here.
I am going to take a guess and say you have a conflict between the credentials your app is using and other credentials you may have installed onto your dev or test machine, i.e. in the credentials file or your app.config.
I would check and make sure you are only using a single method to provide those credentials to the program.
THis link shows the priority the SDK will look for the credentials:
http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html

Amazon S3 : List Objects

I have this code to list objects in the folder.
var accessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
var secretKey = ConfigurationManager.AppSettings["AWSSecretKey"];
using (AmazonS3Client s3Client = new AmazonS3Client(accessKey, secretKey, RegionEndpoint.USEast1 ))
{
var prefix = string.Format(#"{0}/", uniqueKey);
ListObjectsRequest request = new ListObjectsRequest();
request.BucketName = bucketName;
request.Delimiter = "/";
request.Prefix = prefix;
do
{
ListObjectsResponse response = s3Client.ListObjects(request);
This throws an exception when I access the folders :
<uri>/bucketname/profile/ // Throws and exception key not found
<uri>/bucketname/profile/profile.png // This is OK
Image was created using the following path having a READ CannedACL.
<uri>/bucketname/profile//profile.png
Error
String key was not found
QUESTION
Why i cannot access the folders (objects)?
Are folders need to set permissions individually for it to be accessible?
UPDATE
I solved the issue
Bucket names should not have a / character
Client given me a bucket name with this format sample/new
But the true bucket name is only sample

Amazon MWS client library C# AWS Access Key Id error

I am using Amazon C# client library to get product information and keep getting an error " The AWS Access Key Id you provided does not exist in our records." (Yes, I tried the seller forum, but didn't get an answer there). When I use the same Access Key using their scratchpad, I get the correct response. I did see this post (Getting 'The AWS Access Key Id you provided does not exist in our records' error with Amazon MWS) and tried swapping the parameters and that didn't work. Here is my C# code. Any help would be greatly appreciated
string AccessKey = "xxx";
string SecretKey = "xxx";
string AppName = "ProductFunctionsApp";
string AppVersion = "1.0";
string ServiceURL = "https://mws.amazonservices.com/Products/2011-10-01";
string SellerId="xxxx";
string MarketPlaceId = "xxx";//US
//right now MWSAuthToken is only if a developer is using a sellers account
MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig();
config.ServiceURL = ServiceURL;
config.SignatureMethod = "HmacSHA256";
config.SignatureVersion = "2";
MarketplaceWebServiceProductsClient client = new MarketplaceWebServiceProductsClient(AppName, AccessKey, SecretKey, AppVersion, config);
ASINListType type = new ASINListType();
List<string> ASINList = new List<string>();
ASINList.Add("B001E6C08E");
type.ASIN = ASINList;
;
GetCompetitivePricingForASINRequest request = new GetCompetitivePricingForASINRequest();
request.SellerId = SellerId;
request.ASINList = type;
request.MarketplaceId = MarketPlaceId;
GetCompetitivePricingForASINResponse response = client.GetCompetitivePricingForASIN(request);
Some of their API Clients have the class initialization parameters defined in different orders.
So if you copy and paste the initialization code you'll end up with the application name being sent instead of the access key.
var service = new MarketplaceWebServiceProductsClient(
applicationName, applicationVersion, accessKeyId, secretAccessKey, config);
And it's different here:
var service = new FBAInventoryServiceMWSClient(
accessKeyId, secretAccessKey, applicationName, applicationVersion, config);
Just check each one carefully.

Amazon s3 .NET SDK , the bucket you are trying to access must be addressed using specfied endpoint

I am using amazon .NET SDK in widows phone 8 app for uploading images, the code was working fine.Now I get an exception
The bucket you are attempting to access must be addressed using the
specified endpoint. Please send all future requests to this endpoint.
I have updated to latest version of SDK 2.0.2.2, Has anything changed with the update?
My code
string awsID = "myid";
string secretKey = "mysecretkey";
try{
AmazonS3Client s3Client = new AmazonS3Client(awsID, secretKey,RegionEndpoint.USWest1);
string s="";
if (IsolatedStorageSettings.ApplicationSettings.Contains("selectedphoto1"))
{
s = IsolatedStorageSettings.ApplicationSettings["selectedphoto1"] as string;
}
var InputStream = App.GetResourceStream(new Uri("appname;component/Assets /call.png", UriKind.Relative));
var request = new PutObjectRequest()
{
BucketName = "mybucketname",
ContentType="image/png",
Key=s+".jpg",
InputStream = myFileStream,
};
await s3Client.PutObjectAsync(request);
}
catch (Exception ex)
{
Console.Write(ex.InnerException);
}
This is happening because bucket region is incorrect.
Check your region on Amazon console at S3 bucket and configure the same in config file and code.
For example:
AmazonS3Client s3Client = new AmazonS3Client(awsID, secretKey, RegionEndpoint.APNortheast1);
<add key="AWSRegion" value="eu-west-1" />

Categories