我们使用步骤函数定期聚合日志,并使用lambda将日志转发到s3 buucket,limitExceededException来自forward logs lambda,这种情况并非总是随机发生的。
由于我还没有为这个实现编写代码,所以发布一个可复制的示例会很困难。
经过调查,我发现在https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_CreateExportTask.htmlwhere Each account can only have one active (RUNNING or PENDING) export task at a time.
λ码
async invokeForwardingTask(
options: ForwardingTaskInvokingOptions
): Promise<void> {
const { from, logGroupName, to } = options
const date = dayjs.utc(from)
const partitionPrefix = [
`year=${date.format('YYYY')}`,
`month=${date.format('MM')}`,
`day=${date.format('DD')}`,
].join('/')
const categoryPrefix = logGroupName.replace(/^//, '')
await this.cwl
.createExportTask({
logGroupName,
destination: this.logDestination,
from,
to,
destinationPrefix: `${categoryPrefix}/${partitionPrefix}`,
})
.promise()
阶跃函数代码
const logForwarding = new tasks.LambdaInvoke(this, 'Forward a log', {
lambdaFunction: forwarder.lambdaFunction,
inputPath: '$.systemLog',
outputPath: '$.Payload',
timeout: Duration.seconds(
logForwardingRetryConfig.interval.toSeconds() +
logForwardingRetryConfig.interval.toSeconds() *
logForwardingRetryConfig.backOffRate *
(logForwardingRetryConfig.maxAttempts - 1)
),
})
const oneMinWaiting = new sfn.Wait(this, 'Wait for a while', {
time: sfn.WaitTime.duration(Duration.minutes(2)),
})
const choice = new sfn.Choice(this, 'No Logs?')
.when(
sfn.Condition.numberEquals('$.systemLog.length', 0),
new sfn.Succeed(this, 'No more logs')
)
.otherwise(logForwarding)
const definition = logAggregation.next(choice)
choice.afterwards().next(oneMinWaiting).next(choice)
logForwarding.addRetry(logForwardingRetryConfig)
const stateMachine = new StepFunctions(this, 'StepFunctions', {
definition,
})
// Every 1 AM in JST
stateMachine.addEventsRule('cron(0 16 * * ? *)')
您很可能会被从特定API上的Cloudwatch日志中阻止。试着检查你的cloudwatch指标,看看你是否需要提高你的服务级别限制