Uploading to S3 from within an EC2 VPC - ruby

If we're uploading files to S3 from within our AWS VPC, do we have to do anything special other than initiate an upload through the S3 API on the standard URL?
We're planning on using the aws-s3 Ruby gem to do the transfer and just trying to figure out if there are changes we need to make in order to ensure that the data transfer is free.
Thanks in advance!

Data transfer in the form of uploads is always free whether you are in or out of the AWS network. You do however have to pay for LIST/PUT/COPY/POST requests both in and out of network.
You get free transfer OUT of S3 when it is sent to AWS instance, and this is done in the same manner you would do it if you were GETing data outside AWS. They do the resolution to the S3 url and route it internally, no different syntax needed. Again you still pay for the GET request but this time you save money on the transfer bandwidth.
Please do note however if you are connecting to S3 outside the AWS region you are in (IE connecting to S3 Northern VA -> AWS West) you will have to pay for outbound S3 traffic.

Related

Need a way to mount or share s3 or any other aws storage service in windows ec2 instance

We have use case where we want the ability to create shareable drive that would link our ec2 windows instance with any of the storage service (s3 or any other service), such that our user would upload their pdf files in that storage and will be accessible by our windows ec2 instance in which we have program that does pdf files processing. So is there way we can achieve this in aws?
Since your Windows software requires a 'local drive' to detect input files, you could mount an Amazon S3 bucket using utilities such as:
Cloudberry Drive
TntDrive
Mountain Duck
ExpanDrive
Your web application would still be responsible for authenticating users and Uploading objects using presigned URLs - Amazon Simple Storage Service directly to Amazon S3. Your app would also need to determine how to handle the 'output' files so that users can access their converted file.

how to serve node js api through AWS cloudfront?

I am trying to serve my node js API (deployed on AWS EC2 and attached with application load balancer) through cloudfront url, is it possible?
Here are the steps I followed so far -
Created S3 bucket to host static website hosting
Created cloudfront distribution and linked S3 bucket with it. I can access S3 bucket contents with default url generated from cloudfront
Created custom origin for node js instance
Created behavior "api/*" to access node js API through cloudfront.
But when I am trying to access API with following url -
http://d3m30a4naen9t2.cloudfront.net/api/getItems
it throws "not found", it's not 404, this response is from EC2 server however the specified route exists.
Can anyone help please?
I am using ELB. I deployed my code which is on node.js, and everything is working fine. I was facing a lots of problem in ELB but finally we came to stable stage. If you want to serve your APIs then first use SSL which has lesser protocols in other words, use less secure SSL otherwise, your API will not be able to hit from any other source. Simply deploy your code through git or directly from filezilla and run the command on both servers (primary and secondary) as pm2 start index.js/server.js or whatever your main express file is.
Suggestion: Please be careful while selecting security certificates, because on ELB, if you do not follow the correct implementation, you will definitely face the problem of "API not accessible" or "Remote server is unable to connect".

Amazon cloudfront - s3 or ec2?

I have an application hosted on EC2 instance.
Now I want to fetch all the static content used in application from Cloudfront.
Read from a source that Cloudfront uses S3/EC2 or private servers to get the static files.
I can't come to solution what exactly to use? Can I use same EC2 instance for this purpose? Any better option for this implementation?
Amazon CloudFront sits "in front" of your application on Amazon EC2 and/or your content in Amazon S3. It caches content in 50+ locations when people access your application.
For example, let's say you had a web app running on an EC2 instance serving HTML pages, and also some pictures in S3.
You would create a CloudFront distribution and configure two origins: one for your web server and one for your S3 bucket. Behaviours can be configured to tell CloudFront when to use each origin -- for example, serve *.htm URLs from EC2 and *.jpg URLs from S3.
Your users would then access your application via the supplied CloudFront URL. Content will be cached (if appropriate) at one of the 50+ CloudFront locations around the world that is closest to each of your users, resulting in faster response times for your user.
You can also use your own domain name with CloudFront so that it has a more-friendly URL than the one supplied on the CloudFront distribution (which looks like d3i7tv8nzqzfbt.cloudfront.net).
simply Amazon s3 is used for cloud storage where as Amazon EC2(elastic cloud) is used to server web pages(hosting) same as like godaddy.com.

AWS: To redirect or to proxy files

Let me explain dilemma.
I use 3 services from Amazon: EC2, S3 and CloudFront.
EC2 receives an file as upload, stores it in the S3 bucket. Then CloudFront mirrors the S3 bucket. The only limit is to have user friendly URLs.
Which approach to deliver those files is better?
Client > CloudFront > EC2 > S3
Client does a HTTP request to CloudFront URL
Cloudfront forwards the request to EC2
EC2 translates user friendly URL to raw file URL
EC2 reads the file from S3
Client > EC2 ... redirect ... CloudFront > S3
Client does a HTTP request to EC2
EC2 translates user friendly URL to raw file URL
EC2 redirects to CloudFront, witch mirrors the S3
There are two dimensions for this: the speed and the cost.
I see facebook using the second approach when serving profile images
http://graph.facebook.com/platform/picture
You certainly don't want to force the file transfer between S3 and your client to go through your EC2 instance. That will add load to the EC2 instance, increase bandwidth usage, and undoubtedly slow the response to the user.
Your EC2 instance gives you the greatest control over URL format, so you'll want the client to make the initial request to it (to have a "user-friendly" URL). The EC2 instance can just send the client a redirect to the CloudFront or S3 URL that actually has the content, and the client will pull it directly from there without the further involvement of EC2.
I wouldn't bother with CloudFront unless you have an enormous number of requests, or network latency has to be as low as possible.
I personally would just give the files a nice name and a proper content type metatag in S3 when first doing the file upload and, as such, remove your EC2 instances from the download path altogether. You would just serve the clean-url to you client in your HTML content and that clean URL will point directly to you resources in Cloudfront/S3, which has the proper metatags to serve up the desired content-type header.

Sending file from S3 to third party FTP server using CloudFront

I have some files that are stored on S3.
On users request, I want to transfer them to FTP server of a third party site.
Amazon S3 does not support FTP/SFTP.
Currently I am downloading the file from S3 to my local server using S3 APIs and then transferring it to third party FTP server.
S3 --API--> Local --FTP--> Third party FTP
Now, instead I want to transfer the files directly to third party FTP server directly from S3 without downloading it to my local server.
S3 ---CloudFront or Other Service---> Third Party FTP
How can I do it using cloudfront or any other services?
Any Help will be appreciated.
Thanks in advance.
S3 only has APIs to get data to it and from it. It also has an API function to copy data between two buckets, but that's about it.
If you require to transfer data from S3 to other places and want to save the download from S3 to your local machine I suggest you start a t1.micro instance and put a script on it to download the files to it (you won't pay the bandwidth because between S3 and EC2 instance on the same region you don't pay anything and its significantly faster) and then upload from that instance to the remote 3rd party FTP site.

Resources