Skip to content

sdk-v3: Import changes in master branch #786

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
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
192 changes: 93 additions & 99 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,119 +955,113 @@ they may not work as expected in the Lambda environment.
!!err.message.match(/^Function not found:/)
}

_deployToRegion (program, params, region, buffer) {
async _deployToRegion (program, params, region, buffer) {
// sdk v3 todo: Migration of aws.updateConfig.
aws.updateConfig(program, region)

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

return Promise.resolve().then(() => {
if (this._isUseS3(program)) {
const s3Deploy = new S3Deploy(aws.sdk, region)
return s3Deploy.putPackage(params, region, buffer)
}
return null
}).then((code) => {
if (code != null) params.Code = code
}).then(() => {
if (!this._isUseS3(program)) {
console.log(`=> Uploading zip file to AWS Lambda ${region} with parameters:`)
} else {
console.log(`=> Uploading AWS Lambda ${region} with parameters:`)
}
console.log(params)
if (this._isUseS3(program)) {
const s3Deploy = new S3Deploy(aws.sdk, region)
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)

// Migrating to v3.
const lambda = new aws.sdk.Lambda({
region,
apiVersion: '2015-03-31'
})
const lambdaClient = new LambdaClient({ region })
// Migrating to v3.
const lambda = new aws.sdk.Lambda({
region,
apiVersion: '2015-03-31'
})
const lambdaClient = new LambdaClient({ region })

const scheduleEvents = new ScheduleEvents(aws.sdk, region)
const s3Events = new S3Events(aws.sdk, region)
const cloudWatchLogs = new CloudWatchLogs(aws.sdk, region)
const scheduleEvents = new ScheduleEvents(aws.sdk, region)
const s3Events = new S3Events(aws.sdk, region)
const cloudWatchLogs = new CloudWatchLogs(aws.sdk, region)

// Checking function
return lambda.getFunction({
FunctionName: params.FunctionName
}).promise().then(() => {
// Function exists
return this._listEventSourceMappings(lambdaClient, {
const existsFunction = await (async () => {
try {
await lambda.getFunction({
FunctionName: params.FunctionName
}).then((existingEventSourceList) => {
return Promise.all([
this._uploadExisting(lambdaClient, params).then((results) => {
console.log('=> Done uploading. Results follow: ')
console.log(results)
return results
}).then(results => {
return Promise.all([
this._updateScheduleEvents(
scheduleEvents,
results.FunctionArn,
eventSourceList.ScheduleEvents
),
this._updateS3Events(
s3Events,
results.FunctionArn,
eventSourceList.S3Events
),
this._updateTags(
lambdaClient,
results.FunctionArn,
params.Tags)
])
}),
this._updateEventSources(
lambdaClient,
params.FunctionName,
existingEventSourceList,
eventSourceList.EventSourceMappings
),
this._setLogsRetentionPolicy(
cloudWatchLogs,
program,
params.FunctionName
)
])
})
}).catch((err) => {
}).promise()
return true
} catch (err) {
if (!this._isFunctionDoesNotExist(err)) {
throw err
}
// Function does not exist
return this._uploadNew(lambdaClient, params).then((results) => {
console.log('=> Done uploading. Results follow: ')
console.log(results)

return Promise.all([
this._updateEventSources(
lambdaClient,
params.FunctionName,
[],
eventSourceList.EventSourceMappings
),
this._updateScheduleEvents(
scheduleEvents,
results.FunctionArn,
eventSourceList.ScheduleEvents
),
this._updateS3Events(
s3Events,
results.FunctionArn,
eventSourceList.S3Events
),
this._setLogsRetentionPolicy(
cloudWatchLogs,
program,
params.FunctionName
)
])
})
return false
}
})()

if (existsFunction) {
const existingEventSourceList = await this._listEventSourceMappings(lambdaClient, {
FunctionName: params.FunctionName
})
})
const results = await this._uploadExisting(lambdaClient, params)
console.log('=> Done uploading. Results follow: ')
console.log(results)

return Promise.all([
Promise.all([
this._updateScheduleEvents(
scheduleEvents,
results.FunctionArn,
eventSourceList.ScheduleEvents
),
this._updateS3Events(
s3Events,
results.FunctionArn,
eventSourceList.S3Events
),
this._updateTags(
lambdaClient,
results.FunctionArn,
params.Tags)
]),
this._updateEventSources(
lambdaClient,
params.FunctionName,
existingEventSourceList,
eventSourceList.EventSourceMappings
),
this._setLogsRetentionPolicy(
cloudWatchLogs,
program,
params.FunctionName
)
])
} else {
const results = await this._uploadNew(lambdaClient, params)
console.log('=> Done uploading. Results follow: ')
console.log(results)

return Promise.all([
this._updateEventSources(
lambdaClient,
params.FunctionName,
[],
eventSourceList.EventSourceMappings
),
this._updateScheduleEvents(
scheduleEvents,
results.FunctionArn,
eventSourceList.ScheduleEvents
),
this._updateS3Events(
s3Events,
results.FunctionArn,
eventSourceList.S3Events
),
this._setLogsRetentionPolicy(
cloudWatchLogs,
program,
params.FunctionName
)
])
}
}

_printDeployResults (results, isFirst) {
Expand Down
Loading