I am having some strange behaviour when trying to upload files to S3. I am using a Symfony2 Bundle which is just a wrapper for version 1 of the AWS SDK.
First of all, if I run the following code it creates a bucket in S3 and successfully uploads a file to it.
$s3 = $this->container->get('aws_s3');
$s3->createBucket('my.first.test.bucket', 's3-eu-west-1.amazonaws.com');
$response = $s3->createObject('my.first.test.bucket', 'test1.txt', array(
'body' => 'This is my body text.'
));
var_dump($response);
If I then change the file name to 'test2.txt' and rerun this also successfully uploads the file to the bucket, without creating a new bucket with the same name. However, if I then try commenting out the createBucket line I get the following message in the response;
"The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint."
The endpoint it gives me in the response is my.first.test.bucket.s3.amazonaws.com, but if I try this I get a The specified bucket does not exist error. When creating the bucket I tried to use a specific region so I changed the endpoint to my.first.test.bucket.s3-eu-west-1.amazonaws.com but I get the same error which says that the bucket does not exist. I don't believe it's a naming issue as they comply with DNS naming conventions which is the suggested convention by AWS.
It's almost as though my user has permission to create buckets but I'm creating buckets without proper permissions for my user. I can't see where I would have gone wrong though as my IAM user has full access to S3 by the following profile policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}
I have even tried created a bucket manually in S3 and added a bucket policy to grant access but every endpoint I try results in the same bucket not found error.
For once, I'm really hoping I've made a stupid mistake. Any ideas?
EDIT: I have not set up the bucket for Static website hosting so I should not need the endpoint s3-website-eu-west-1.amazonaws.com, but just in case I tried that too with the same result.