当我们从S3触发Lambda函数时,可以通过以下步骤获取Lambda是否被触发的日志,使用Terraform进行配置:
resource "aws_s3_bucket" "example_bucket" {
bucket = "example-bucket"
}
resource "aws_lambda_function" "example_lambda" {
function_name = "example-lambda"
...
}
resource "aws_s3_bucket_notification" "example_notification" {
bucket = aws_s3_bucket.example_bucket.id
lambda_function {
lambda_function_arn = aws_lambda_function.example_lambda.arn
events = ["s3:ObjectCreated:*"]
}
}
resource "aws_cloudwatch_log_group" "example_log_group" {
name = "/aws/lambda/example-lambda"
}
resource "aws_lambda_function" "example_lambda" {
function_name = "example-lambda"
...
tracing_config {
mode = "Active"
}
environment {
variables = {
...
}
}
vpc_config {
...
}
# 配置日志记录
environment {
variables = {
AWS_LAMBDA_LOG_GROUP_NAME = aws_cloudwatch_log_group.example_log_group.name
AWS_LAMBDA_LOG_STREAM_NAME = "example-lambda"
}
}
}
aws logs filter-log-events --log-group-name /aws/lambda/example-lambda --log-stream-name example-lambda
以上是使用Terraform配置S3触发Lambda函数并获取日志的步骤。请注意,这里没有提及任何特定的腾讯云产品,因此无法提供腾讯云相关产品和链接。如需了解腾讯云的相关产品,请参考腾讯云官方文档或咨询腾讯云支持团队。
领取专属 10元无门槛券
手把手带您无忧上云