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');
13
13
const { S3Client } = require ( '@aws-sdk/client-s3' ) ;
14
14
const { SSMClient } = require ( '@aws-sdk/client-ssm' ) ;
15
15
const { STSClient } = require ( '@aws-sdk/client-sts' ) ;
16
+ const { Upload } = require ( '@aws-sdk/lib-storage' ) ;
16
17
17
18
// Map service names to their client classes
18
19
const CLIENT_MAP = {
@@ -63,12 +64,22 @@ class AWSClientFactory {
63
64
/**
64
65
* Send a command to an AWS service
65
66
* @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
67
68
* @param {Object } clientConfig - Optional client configuration override
68
69
* @returns {Promise } Result of the AWS API call
69
70
*/
70
71
async send ( serviceName , command , clientConfig = { } ) {
71
72
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
+
72
83
return client . send ( command ) ;
73
84
}
74
85
}
Original file line number Diff line number Diff line change @@ -230,11 +230,13 @@ const COMMAND_MAP = {
230
230
*/
231
231
function getCommand ( serviceName , methodName ) {
232
232
const serviceCommands = COMMAND_MAP [ serviceName ] ;
233
+
233
234
if ( ! serviceCommands ) {
234
235
throw new Error ( `Unknown AWS service: ${ serviceName } ` ) ;
235
236
}
236
237
237
238
const CommandClass = serviceCommands [ methodName ] ;
239
+
238
240
if ( ! CommandClass ) {
239
241
throw new Error ( `Unknown method '${ methodName } ' for service '${ serviceName } '` ) ;
240
242
}
@@ -250,7 +252,15 @@ function getCommand(serviceName, methodName) {
250
252
* @returns {Object } Command instance
251
253
*/
252
254
function createCommand ( serviceName , methodName , params = { } ) {
255
+ if ( serviceName === 'S3' && methodName === 'upload' ) {
256
+ return {
257
+ _isUploadRequest : true ,
258
+ params,
259
+ } ;
260
+ }
261
+
253
262
const CommandClass = getCommand ( serviceName , methodName ) ;
263
+
254
264
return new CommandClass ( params ) ;
255
265
}
256
266
Original file line number Diff line number Diff line change @@ -100,9 +100,21 @@ class AwsInvoke {
100
100
return this . provider . request ( 'Lambda' , 'invoke' , params ) ;
101
101
}
102
102
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
+
103
115
log ( invocationReply ) {
104
116
if ( invocationReply . Payload ) {
105
- const response = JSON . parse ( invocationReply . Payload ) ;
117
+ const response = JSON . parse ( this . payloadToString ( invocationReply . Payload ) ) ;
106
118
107
119
writeText ( JSON . stringify ( response , null , 4 ) ) ;
108
120
}
Original file line number Diff line number Diff line change @@ -1798,10 +1798,20 @@ class AwsProvider {
1798
1798
* @private
1799
1799
*/
1800
1800
_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
+
1802
1812
return buildClientConfig ( {
1803
1813
region : this . getRegion ( ) ,
1804
- credentials : credentials . accessKeyId ? credentials : undefined ,
1814
+ credentials,
1805
1815
} ) ;
1806
1816
}
1807
1817
Original file line number Diff line number Diff line change 41
41
"@aws-sdk/client-ssm" : " ^3.588.0" ,
42
42
"@aws-sdk/client-sts" : " ^3.588.0" ,
43
43
"@aws-sdk/lib-dynamodb" : " ^3.588.0" ,
44
+ "@aws-sdk/lib-storage" : " ^3.588.0" ,
44
45
"@aws-sdk/credential-providers" : " ^3.588.0" ,
45
46
"@serverless/utils" : " ^6.13.1" ,
46
47
"ajv" : " ^8.12.0" ,
You can’t perform that action at this time.
0 commit comments