AWS Lambda出现意外行为

时间:2017-12-12 15:10:09

标签: kotlin aws-lambda serverless-framework

我做了什么

我使用aws-kotlin-jvm-maven模板中的无服务器cli创建了一个项目。之后我以这种方式编辑了我的serverless.yml模板:

service: test
provider:
  name: aws
  runtime: java8
  region: eu-west-1
package:
  artifact: target/test-1.0.0.jar
functions:
  hello:
    handler: com.example.Handler
    events:
      - schedule: rate(2 minutes)

我以这种方式编辑了我的处理程序:

class Handler:RequestHandler<Map<String, Any>, ApiGatewayResponse> {
    override fun handleRequest(input:Map<String, Any>, context:Context):ApiGatewayResponse {
        BasicConfigurator.configure()
        LOG.info("Hello, World!")
        return ApiGatewayResponse()
    }
    companion object {
        private val LOG = Logger.getLogger(Handler::class.java)
    }
}

我期待我的Lambda每2分钟运行一次,记录一个&#34; Hello,World!&#34;在CloudWatch上,每2分钟一次。

我的问题

我在cloudWatch日志中找到的内容如下:

第一轮: &#34;你好,世界!&#34;

第二轮: &#34;你好,世界!&#34; &#34;你好,世界!&#34;

第三轮: &#34;你好,世界!&#34; &#34;你好,世界!&#34; &#34;你好,世界!&#34;

......等等。

有关此处发生的事情的任何建议吗?

1 个答案:

答案 0 :(得分:1)

我通过将日志记录依赖项更改为:

来解决此问题
<dependency>
    <groupId>io.symphonia</groupId>
    <artifactId>lambda-logging</artifactId>
    <version>1.0.0</version>
</dependency>

我在这里找到了一篇非常有用的文章:https://blog.symphonia.io/a-love-letter-to-lambda-logging-974b0eb49273