aws / aws-sdk-php-zf2

ZF2 module for using the AWS SDK for PHP to interact with AWS services like S3, DynamoDB, SQS, EC2, etc.
http://aws.amazon.com/sdkforphp/
Apache License 2.0
103 stars 63 forks source link

Add S3 helper #7

Closed bakura10 closed 11 years ago

bakura10 commented 11 years ago

Hi,

I may be completely wrong, but until now, what I've done is simply storing the full path to the S3 object in my database. However it's a mess when you want to go to CloudFront to change the links everywhere.

So now I just store the bucket name and the object name. Therefore I thought it would be nice to have a view helper that would generate a link to an S3 object, and be able to configure the view helper to use CloudFront, so that all links are automatically changed to CloudFront.

Basic usage would be:

<?= $this->s3Link('/media/file.css', 'my-bucket'); ?>
// Output 'https://my-bucket.s3.amazonaws.com/media/file.css'

// If it's configured to CloudFront, bucket become optional:
<?= $this->s3Link('/media/file.css', 'my-bucket'); ?>
// Output 'https://domainname.cloudfront.net/media/file.css'

What do you think of such a feature?

Before merging I'd like to add an option to sign URL, as well as an option to map a bucket name to a cloudfront domain (I think this can be a problem, people using two s3 buckets I suppose they have two cloudfront domain to avoid name clashes).

I'm just not really satisfied with the naming, as s3Link may output a cloudfront link, but this is the only solution I've found to change ALL the links by simply changing in option in the config (but it may lead to side-effects ? So maybe it's simpler to write two differnet helpers ?.

ping @ocramius too for his nice ideas everytime =)

EDIT : I finally went with a simpler strategy with two view helpers. If someone want to go from S3 to CloudFront I think it's pretty easy to do a search-replace to replace s3Link by cloudFrontLink. But maybe you have a better idea.

@jeremeamia I wonder how to create a signed URL for CloudFront ? It seems it is much more complicated than for S3.

jeremeamia commented 11 years ago

This definitely seems like a cool feature for the module. Here's more info about CloudFront URL signing: http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/service-cloudfront.html. Let me know if you have any more questions. It's a little bit more intense than S3 URLs, so make sure to read the material at that link and the other page that it links too. Hint: requires OpenSSL.

I'll check and see if I need another CLA for this.

bakura10 commented 11 years ago

Thanks. I'll have a look at that. I just realized that I need to make an option to select between http and https, as CloudFront appears to be around 30% more expensive for HTTPS requests.

bakura10 commented 11 years ago

I've made some changes @jeremeamia . I think we can keep this simple and only use canned policy for generating URL (supporting the custom policy would make the view helper harder to use... people can extend it if they want more edgy cases). The private key and key pair should be specified in Aws configuration.

Can you make a quick review @ocramius ?

If it's good, I'll write tests :).

bakura10 commented 11 years ago

I added tests, and an option to specify a default bucket. I think it can be merged (but I'd like some review first :p).

bakura10 commented 11 years ago

@jeremeamia completely out of context question: is there some kind of Elastic Simple Workflow SDK for PHP planned ? (I mean, not like it is currently in the PHP SDK, a real SDK like Flow in Java).

I thought about creating one but it's a lot of work, but it would be definitely nice. It sounds like an interesting service but it's currently not easy to use it.

jeremeamia commented 11 years ago

Did I send you another CLA yet? I was at Symfony Live this week, and I can't remember if I sent it before that yet.

bakura10 commented 11 years ago

I already signed one. Do I need to sign one for each PR ?

Envoyé de mon iPhone

Le 27 mai 2013 à 05:32, Jeremy Lindblom notifications@github.com a écrit :

Did I send you another CLA yet? I was at Symfony Live this week, and I can't remember if I sent it before that yet.

— Reply to this email directly or view it on GitHub.

jeremeamia commented 11 years ago

I think so, but I will double check on Tuesday. I'll go ahead and send you the CLA again tomorrow just in case. I believe we require one for every "substantial" contribution.

jeremeamia commented 11 years ago

The CLA has been received and processed. Thank you. As for the HTTP vs. HTTPS discussion, we believe that HTTPS should be the default. Security first. Please make that adjustment and ping me back. Then we can do a final review of everything and get it merged. Thanks Michaël!

bakura10 commented 11 years ago

Done @jeremeamia . I've also added a Changelog, change it if it does not mean your own versioning scheme ;-).

jeremeamia commented 11 years ago

I pulled your work down into a branch and did some additional work. If it looks good to you then I'll merge into master and tag as 1.0.2. See https://github.com/aws/aws-sdk-php-zf2/commit/1d8ea71c16078871052b9b06ac428b324ef29a77