File tree Expand file tree Collapse file tree 5 files changed +48
-4
lines changed Expand file tree Collapse file tree 5 files changed +48
-4
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const { LambdaClient } = require('@aws-sdk/client-lambda');
1313const { S3Client } = require ( '@aws-sdk/client-s3' ) ;
1414const { SSMClient } = require ( '@aws-sdk/client-ssm' ) ;
1515const { STSClient } = require ( '@aws-sdk/client-sts' ) ;
16+ const { Upload } = require ( '@aws-sdk/lib-storage' ) ;
1617
1718// Map service names to their client classes
1819const CLIENT_MAP = {
@@ -63,12 +64,22 @@ class AWSClientFactory {
6364 /**
6465 * Send a command to an AWS service
6566 * @param {string } serviceName - Name of the AWS service
66- * @param {Object } command - AWS SDK v3 command instance
67+ * @param {Object } command - AWS SDK v3 command instance or special upload indicator
6768 * @param {Object } clientConfig - Optional client configuration override
6869 * @returns {Promise } Result of the AWS API call
6970 */
7071 async send ( serviceName , command , clientConfig = { } ) {
7172 const client = this . getClient ( serviceName , clientConfig ) ;
73+
74+ if ( serviceName === 'S3' && command . _isUploadRequest ) {
75+ const upload = new Upload ( {
76+ client,
77+ params : command . params ,
78+ } ) ;
79+
80+ return upload . done ( ) ;
81+ }
82+
7283 return client . send ( command ) ;
7384 }
7485}
Original file line number Diff line number Diff line change @@ -230,11 +230,13 @@ const COMMAND_MAP = {
230230 */
231231function getCommand ( serviceName , methodName ) {
232232 const serviceCommands = COMMAND_MAP [ serviceName ] ;
233+
233234 if ( ! serviceCommands ) {
234235 throw new Error ( `Unknown AWS service: ${ serviceName } ` ) ;
235236 }
236237
237238 const CommandClass = serviceCommands [ methodName ] ;
239+
238240 if ( ! CommandClass ) {
239241 throw new Error ( `Unknown method '${ methodName } ' for service '${ serviceName } '` ) ;
240242 }
@@ -250,7 +252,15 @@ function getCommand(serviceName, methodName) {
250252 * @returns {Object } Command instance
251253 */
252254function createCommand ( serviceName , methodName , params = { } ) {
255+ if ( serviceName === 'S3' && methodName === 'upload' ) {
256+ return {
257+ _isUploadRequest : true ,
258+ params,
259+ } ;
260+ }
261+
253262 const CommandClass = getCommand ( serviceName , methodName ) ;
263+
254264 return new CommandClass ( params ) ;
255265}
256266
Original file line number Diff line number Diff line change @@ -100,9 +100,21 @@ class AwsInvoke {
100100 return this . provider . request ( 'Lambda' , 'invoke' , params ) ;
101101 }
102102
103+ payloadToString ( payload ) {
104+ if ( payload instanceof Uint8Array ) {
105+ return new TextDecoder ( ) . decode ( payload ) ;
106+ }
107+
108+ if ( Buffer . isBuffer ( payload ) ) {
109+ return payload . toString ( ) ;
110+ }
111+
112+ return payload ;
113+ }
114+
103115 log ( invocationReply ) {
104116 if ( invocationReply . Payload ) {
105- const response = JSON . parse ( invocationReply . Payload ) ;
117+ const response = JSON . parse ( this . payloadToString ( invocationReply . Payload ) ) ;
106118
107119 writeText ( JSON . stringify ( response , null , 4 ) ) ;
108120 }
Original file line number Diff line number Diff line change @@ -1798,10 +1798,20 @@ class AwsProvider {
17981798 * @private
17991799 */
18001800 _getV3BaseConfig ( ) {
1801- const credentials = this . getCredentials ( ) ;
1801+ // Convert v2 credentials format to v3 format
1802+ const { credentials : v2Creds } = this . getCredentials ( ) ;
1803+ const credentials =
1804+ v2Creds && v2Creds . accessKeyId
1805+ ? {
1806+ accessKeyId : v2Creds . accessKeyId ,
1807+ secretAccessKey : v2Creds . secretAccessKey ,
1808+ sessionToken : v2Creds . sessionToken ,
1809+ }
1810+ : undefined ;
1811+
18021812 return buildClientConfig ( {
18031813 region : this . getRegion ( ) ,
1804- credentials : credentials . accessKeyId ? credentials : undefined ,
1814+ credentials,
18051815 } ) ;
18061816 }
18071817
Original file line number Diff line number Diff line change 4141 "@aws-sdk/client-ssm" : " ^3.588.0" ,
4242 "@aws-sdk/client-sts" : " ^3.588.0" ,
4343 "@aws-sdk/lib-dynamodb" : " ^3.588.0" ,
44+ "@aws-sdk/lib-storage" : " ^3.588.0" ,
4445 "@aws-sdk/credential-providers" : " ^3.588.0" ,
4546 "@serverless/utils" : " ^6.13.1" ,
4647 "ajv" : " ^8.12.0" ,
You can’t perform that action at this time.
0 commit comments