Gulp Upload file to S3

For uploading file on S3 we use gulp-s3 Module. To use this module we must have gulp and gulp-cli already installed.
First we need to create a aws.json file for credentials.
The format for file is like

  "key": "AKIAI3Z7CUAFHG53DMJA",
  "secret": "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",
  "bucket": "",
  "region": "eu-west-1"

Now we first need to install gulp-s3 using gulp i –save gulp-s3 Command.
Once module is installed we will create a task for it.

var gulp = require('gulp'),
    s3 = require("gulp-s3"),
    inject = require('gulp-inject'),
    fs = require('fs'),
    s3Url = "";

const DIR = 'build/';

var transformUploadToS3 = function(filepath){
		filepath = filepath.replace(DIR,s3Url);
		arguments[0] = filepath + '?v=' + time;
	return inject.transform.apply(inject.transform, arguments);

	var aws = JSON.parse(fs.readFileSync('./aws.json'));

gulp.task("create-s3-index", function(){
	var	target = gulp.src('./src/index.html'),
		filesources = [DIR+"static.min.js"];

	return 	target.pipe(inject(gulp.src(filesources,{read: false}),
				transform: transformUploadToS3

In the above code after creating the minified files (js/css) we are uploading the files to s3 using moveToS3 command and after that we are injecting the s3 file path url to index.html file create-s3-index command.

3 thoughts on “Gulp Upload file to S3

  • September 28, 2017 at 11:42 am

    My family members every time say that I am killing my time here at web, except I know I am getting familiarity every day by reading thes good articles or reviews.

  • September 28, 2017 at 7:43 pm

    I got this site from my pal who informed me about this website and at the moment this time I am visiting this web page and reading very informative articles or reviews at this place.

  • October 4, 2017 at 11:01 am

    It’s great that you are getting thoughts from this post as well as from our argument made at this time.


Leave a Reply

Your email address will not be published. Required fields are marked *