【问题标题】:How do I pass command line arguments to a Lambda function in Serverless/Bref?如何将命令行参数传递给 Serverless/Bref 中的 Lambda 函数?
【发布时间】:2019-12-20 04:31:54
【问题描述】:

我正在使用 Bref(使用无服务器)在 AWS Lambda 上运行 Symfony 4 (PHP) 应用程序。

Bref 为 Symfony 的 bin/console 二进制文件提供了一层。 Lambda 函数的无服务器配置如下所示:

functions:
    console:
        handler: bin/console
        name: 'mm-console'
        description: 'Symfony 4 console'
        timeout: 120 # in seconds
        layers:
            - ${bref:layer.php-73} # PHP
            - ${bref:layer.console} # The "console" layer

使用上面的方法,我可以在 Lambda 上运行 vendor/bin/bref cli mm-console -- mm:find-matches 来运行 bin/console mm:find-matches

如果我想在 Lambda 上按计划运行mm:find-matches 控制台命令怎么办? 我试过这个:

functions:
    mm-find-matches:
        handler: "bin/console mm:find-matches"
        name: 'mm-find-matches'
        description: 'Find mentor matches'
        timeout: 120
        layers:
            - ${bref:layer.php-73} # PHP
            - ${bref:layer.console} # The "console" layer
        schedule:
            rate: rate(2 hours)

但是“bin/console mm:find-matches”不是有效的处理程序。 如何按计划将mm:find-matches 命令传递给bin/console 函数?

【问题讨论】:

    标签: aws-lambda serverless-framework serverless aws-serverless bref


    【解决方案1】:

    您可以通过调度事件输入传递命令行参数,如下所示:

    functions:
        console:
            handler: bin/console
            name: 'mm-console'
            description: 'Symfony 4 console'
            timeout: 120 # in seconds
            layers:
                - ${bref:layer.php-73} # PHP
                - ${bref:layer.console} # The "console" layer
            events:
                - schedule:
                    input:
                        cli: "mm:find-matches --env=test"
                    rate: rate(2 hours)
                    enabled: true
    

    尽管在this bref github issue 上有一些关于使用 cli 控制台应用程序是否是最佳解决方案的讨论,而不是编写引导内核并执行您希望命令执行的特定操作的 PHP 函数。

    【讨论】:

      猜你喜欢
      • 2012-08-13
      • 2013-12-23
      • 2015-04-17
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      • 2013-10-11
      • 1970-01-01
      • 2012-09-01
      相关资源
      最近更新 更多