【问题标题】:I cant understand this syntax error in AWS lambda, while writing lambda for stopping a ecs task in a service在编写 lambda 以停止服务中的 ecs 任务时,我无法理解 AWS lambda 中的此语法错误
【发布时间】:2020-01-21 03:50:33
【问题描述】:
 - import json
       import boto3
       
       client = boto3.client('ecs')
       
       def lambda_handler(event, context):
           return {
              response = client.stop_task(
              cluster='newCluster',
              task='d3a857b8f2e1463d85265e08b6dfd9f3',
              reason='none'
                                          )
                   }

我已经写了这个 lambda,但是当我测试它时,它显示如下语法错误

回应: { "errorMessage": "模块 'lambda_function' 中的语法错误:无效语法(lambda_function.py,第 8 行)", "errorType": "Runtime.UserCodeSyntaxError", “堆栈跟踪”: [ " 文件 "/var/task/lambda_function.py" 第 8 行\n 响应 = client.stop_task(\n" ] }

请求 ID: "9cb74885-0171-4ed9-9e6f-44e50480139b"

函数日志:START RequestId:9cb74885-0171-4ed9-9e6f-44e50480139b 版本:$LATEST [错误] Runtime.UserCodeSyntaxError:语法错误 模块“lambda_function”:语法无效(lambda_function.py,第 8 行) Traceback(最近一次调用最后一次):文件 “/var/task/lambda_function.py”第 8 行 response = client.stop_task(END RequestId: 9cb74885-0171-4ed9-9e6f-44e50480139b REPORT RequestId: 9cb74885-0171-4ed9-9e6f-44e50480139b 持续时间:27.35 毫秒 持续时间:100 毫秒内存大小:128 MB 使用的最大内存:56 MB 初始化 持续时间:108.01 毫秒 XRAY TraceId: 1-5d846522-6de3bafd93f9f6ddd732c151 SegmentId: 5c86ef0b79d59359 采样:假

【问题讨论】:

    标签: aws-lambda amazon-ecs


    【解决方案1】:
    import json
           import boto3
    
           client = boto3.client('ecs')
    
           def lambda_handler(event, context):
    response=client.stop_task(cluster='newCluster',task='d3a857b8f2e1463d85265e08b6dfd9f3',reason='none')
    

    我刚刚删除了 return 和它的大括号,它起作用了。

    【讨论】:

      【解决方案2】:
      • 值得删除response 或仅返回测试响应,只需通过删除它进行检查,然后稍后整理代码。
      return {
              client.stop_task(cluster='newCluster',task='d3a857b8f2e1463d85265e08b6dfd9f3',reason='none')
          }
      
      • 或者值得做这样的事情,否则响应将无法到达。
      response = client.stop_task(
                    cluster='newCluster',
                    task='d3a857b8f2e1463d85265e08b6dfd9f3',
                    reason='none')
      return response
      
      
      • 值得将 ARN 用于任务和集群并检查其工作原理docs attached
      • 这就是我在我的工作代码中使用它的方式,原因是可选的。(这里我刚刚替换了该变量的值以进行解释)
              client.stop_task(
                  cluster='arn:aws:ecs:us-east-1:xxxxxxxxxxxx:cluster/dev',
                  task='arn:aws:ecs:us-east-1:xxxxxxxxxxxx:task/1de5e17a-422a-4ac4-a493-371970d6d4d6')
      

      【讨论】:

        猜你喜欢
        • 2023-04-07
        • 2020-03-12
        • 2018-03-19
        • 1970-01-01
        • 2020-03-02
        • 2021-11-29
        • 1970-01-01
        • 1970-01-01
        • 2017-09-20
        相关资源
        最近更新 更多