Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,20 +958,20 @@ they may not work as expected in the Lambda environment.
async _deployToRegion (program, params, region, buffer) {
// sdk v3 todo: Migration of aws.updateConfig.
aws.updateConfig(program, region)
const config = { region }

console.log('=> Reading event source file to memory')
const eventSourceList = this._eventSourceList(program)

if (this._isUseS3(program)) {
const s3Deploy = new S3Deploy(aws.sdk, region)
const s3Deploy = new S3Deploy(config)
params.Code = await s3Deploy.putPackage(params, region, buffer)
console.log(`=> Uploading AWS Lambda ${region} with parameters:`)
} else {
console.log(`=> Uploading zip file to AWS Lambda ${region} with parameters:`)
}
console.log(params)

const config = { region }
const lambdaClient = new LambdaClient(config)
// Migrating to v3.
const scheduleEvents = new ScheduleEvents(aws.sdk, region)
Expand Down
42 changes: 18 additions & 24 deletions lib/s3_deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

const process = require('process')
const crypto = require('crypto')

const {
S3Client,
CreateBucketCommand,
PutObjectCommand
} = require('@aws-sdk/client-s3')

// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createBucket-property
const S3_LOCATION_POSSIBLE_VALUES = [
'EU',
Expand Down Expand Up @@ -33,12 +40,8 @@ const S3_LOCATION_POSSIBLE_VALUES = [
]

class S3Deploy {
constructor (aws, region) {
// Authenticated `aws` object in `lib/main.js`
this.s3 = new aws.S3({
region,
apiVersion: '2006-03-01'
})
constructor (config) {
this.client = new S3Client(config)
}

_md5 (str) {
Expand Down Expand Up @@ -107,30 +110,21 @@ class S3Deploy {
LocationConstraint: s3Location
}
}
return new Promise((resolve, reject) => {
this.s3.createBucket(_params, (err, data) => {
if (err) {
// Ignored created
if (err.code === 'BucketAlreadyOwnedByYou') return resolve({})
return reject(err)
}
resolve(data)
})
})
try {
return this.client.send(new CreateBucketCommand(_params))
} catch (err) {
// Ignored created
if (err.code === 'BucketAlreadyOwnedByYou') return {}
throw err
}
}

_putObject (params, buffer) {
const _params = {
return this.client.send(new PutObjectCommand({
Body: buffer,
Bucket: params.bucketName,
Key: params.s3Key
}
return new Promise((resolve, reject) => {
this.s3.putObject(_params, (err, data) => {
if (err) reject(err)
resolve(data)
})
})
}))
}

putPackage (params, region, buffer) {
Expand Down
Loading
Loading