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
54 changes: 22 additions & 32 deletions lib/cloudwatch_logs.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
'use strict'

const {
CloudWatchLogsClient,
CreateLogGroupCommand,
PutRetentionPolicyCommand
} = require('@aws-sdk/client-cloudwatch-logs')

class CloudWatchLogs {
constructor (aws, region) {
// Authenticated `aws` object in `lib/main.js`
this.lambda = new aws.Lambda({
region,
apiVersion: '2015-03-31'
})
this.cloudwatchlogs = new aws.CloudWatchLogs({
apiVersion: '2014-03-28'
})
constructor (config) {
this.client = new CloudWatchLogsClient(config)
}

_logGroupName (params) {
return `/aws/lambda/${params.FunctionName}`
}

_createLogGroup (params) {
return new Promise((resolve, reject) => {
this.cloudwatchlogs.createLogGroup({
try {
return this.client.send(new CreateLogGroupCommand({
logGroupName: this._logGroupName(params)
}, (err, data) => {
if (err) {
if (err.code === 'ResourceAlreadyExistsException') {
// If it exists it will result in an error but there is no problem.
return resolve({})
}
return reject(err)
}

resolve(data)
})
})
}))
} catch (err) {
if (err.code === 'ResourceAlreadyExistsException') {
// If it exists it will result in an error but there is no problem.
return {}
}
throw err
}
}

_putRetentionPolicy (params) {
return new Promise((resolve, reject) => {
this.cloudwatchlogs.putRetentionPolicy({
logGroupName: this._logGroupName(params),
retentionInDays: params.retentionInDays
}, (err, data) => {
if (err) return reject(err)
resolve(data)
})
})
return this.client.send(new PutRetentionPolicyCommand({
logGroupName: this._logGroupName(params),
retentionInDays: params.retentionInDays
}))
}

setLogsRetentionPolicy (params) {
Expand Down
5 changes: 3 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,12 @@ they may not work as expected in the Lambda environment.
}
console.log(params)

const lambdaClient = new LambdaClient({ region })
const config = { region }
const lambdaClient = new LambdaClient(config)
// Migrating to v3.
const scheduleEvents = new ScheduleEvents(aws.sdk, region)
const s3Events = new S3Events(aws.sdk, region)
const cloudWatchLogs = new CloudWatchLogs(aws.sdk, region)
const cloudWatchLogs = new CloudWatchLogs(config)

const existsFunction = await (async () => {
try {
Expand Down
Loading
Loading