@@ -13,6 +13,7 @@ const dotenv = require('dotenv')
1313const proxy = require ( 'proxy-agent' )
1414const ScheduleEvents = require ( path . join ( __dirname , 'schedule_events' ) )
1515const S3Events = require ( path . join ( __dirname , 's3_events' ) )
16+ const S3Deploy = require ( path . join ( __dirname , 's3_deploy' ) )
1617const CloudWatchLogs = require ( path . join ( __dirname , 'cloudwatch_logs' ) )
1718
1819const AWSXRay = require ( 'aws-xray-sdk-core' )
@@ -177,10 +178,10 @@ so you can easily test run multiple events.
177178 }
178179
179180 _isUseS3 ( program ) {
180- return program . deployS3Bucket != null &&
181- program . deployS3Key != null &&
182- program . deployS3Bucket . length > 0 &&
183- program . deployS3Key . length > 0
181+ if ( typeof program . deployUseS3 === 'boolean' ) {
182+ return program . deployUseS3
183+ }
184+ return program . deployUseS3 === 'true'
184185 }
185186
186187 _params ( program , buffer ) {
@@ -219,8 +220,8 @@ so you can easily test run multiple events.
219220
220221 if ( this . _isUseS3 ( program ) ) {
221222 params . Code = {
222- S3Bucket : program . deployS3Bucket ,
223- S3Key : program . deployS3Key
223+ S3Bucket : null ,
224+ S3Key : null
224225 }
225226 } else {
226227 params . Code = { ZipFile : buffer }
@@ -779,23 +780,6 @@ they may not work as expected in the Lambda environment.
779780 } )
780781 }
781782
782- _s3PutObject ( program , region , buffer ) {
783- this . _awsConfigUpdate ( program , region )
784- const s3 = new aws . S3 ( )
785- return new Promise ( ( resolve , reject ) => {
786- const params = {
787- Body : buffer ,
788- Bucket : program . deployS3Bucket ,
789- Key : program . deployS3Key
790- }
791- console . log ( `=> Uploading zip file to S3 ${ region } ` )
792- s3 . putObject ( params , ( err , data ) => {
793- if ( err ) reject ( err )
794- resolve ( data )
795- } )
796- } )
797- }
798-
799783 _awsConfigUpdate ( program , region ) {
800784 const awsSecurity = { region : region }
801785
@@ -832,23 +816,35 @@ they may not work as expected in the Lambda environment.
832816 ! ! err . message . match ( / ^ F u n c t i o n n o t f o u n d : / )
833817 }
834818
835- _deployToRegion ( program , params , region ) {
819+ _deployToRegion ( program , params , region , buffer ) {
820+ this . _awsConfigUpdate ( program , region )
821+
836822 console . log ( '=> Reading event source file to memory' )
837823 const eventSourceList = this . _eventSourceList ( program )
838824
839825 return Promise . resolve ( ) . then ( ( ) => {
826+ if ( this . _isUseS3 ( program ) ) {
827+ const s3Deploy = new S3Deploy ( aws , region )
828+ return s3Deploy . putPackage ( params , region , buffer )
829+ }
830+ return null
831+ } ) . then ( ( code ) => {
832+ if ( code != null ) params . Code = code
833+ } ) . then ( ( ) => {
840834 if ( ! this . _isUseS3 ( program ) ) {
841835 console . log ( `=> Uploading zip file to AWS Lambda ${ region } with parameters:` )
842836 } else {
843837 console . log ( `=> Uploading AWS Lambda ${ region } with parameters:` )
844838 }
845839 console . log ( params )
846840
847- this . _awsConfigUpdate ( program , region )
848- const lambda = new aws . Lambda ( { apiVersion : '2015-03-31' } )
849- const scheduleEvents = new ScheduleEvents ( aws )
850- const s3Events = new S3Events ( aws )
851- const cloudWatchLogs = new CloudWatchLogs ( aws )
841+ const lambda = new aws . Lambda ( {
842+ region : region ,
843+ apiVersion : '2015-03-31'
844+ } )
845+ const scheduleEvents = new ScheduleEvents ( aws , region )
846+ const s3Events = new S3Events ( aws , region )
847+ const cloudWatchLogs = new CloudWatchLogs ( aws , region )
852848
853849 // Checking function
854850 return lambda . getFunction ( {
@@ -945,15 +941,17 @@ they may not work as expected in the Lambda environment.
945941 const regions = program . region . split ( ',' )
946942 return this . _archive ( program ) . then ( ( buffer ) => {
947943 console . log ( '=> Reading zip file to memory' )
948- if ( this . _isUseS3 ( program ) ) {
949- return this . _s3PutObject ( program , regions [ 0 ] , buffer )
950- }
951944 return buffer
952945 } ) . then ( ( buffer ) => {
953946 const params = this . _params ( program , buffer )
954947
955948 return Promise . all ( regions . map ( ( region ) => {
956- return this . _deployToRegion ( program , params , region )
949+ return this . _deployToRegion (
950+ program ,
951+ params ,
952+ region ,
953+ this . _isUseS3 ( program ) ? buffer : null
954+ )
957955 } ) ) . then ( results => {
958956 this . _printDeployResults ( results , true )
959957 } )
0 commit comments