0
votes
 - import json
       import boto3

       client = boto3.client('ecs')

       def lambda_handler(event, context):
           return {
              response = client.stop_task(
              cluster='newCluster',
              task='d3a857b8f2e1463d85265e08b6dfd9f3',
              reason='none'
                                          )
                   }

I have written this lambda, but when I test it , it shows syntax error like below

Response: { "errorMessage": "Syntax error in module 'lambda_function': invalid syntax (lambda_function.py, line 8)", "errorType": "Runtime.UserCodeSyntaxError", "stackTrace": [ " File \"/var/task/lambda_function.py\" Line 8\n response = client.stop_task(\n" ] }

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

Function Logs: START RequestId: 9cb74885-0171-4ed9-9e6f-44e50480139b Version: $LATEST [ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'lambda_function': invalid syntax (lambda_function.py, line 8) Traceback (most recent call last):   File "/var/task/lambda_function.py" Line 8            response = client.stop_task( END RequestId: 9cb74885-0171-4ed9-9e6f-44e50480139b REPORT RequestId: 9cb74885-0171-4ed9-9e6f-44e50480139b Duration: 27.35 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 56 MB Init Duration: 108.01 ms
XRAY TraceId: 1-5d846522-6de3bafd93f9f6ddd732c151 SegmentId: 5c86ef0b79d59359 Sampled: false

2

2 Answers

0
votes
  • Worth removing the response or return just the response for testing just check by removing it and then tidy up the code later.
return {
        client.stop_task(cluster='newCluster',task='d3a857b8f2e1463d85265e08b6dfd9f3',reason='none')
    }
  • Or worth doing something like this other wise the response is going to be unreachable.
response = client.stop_task(
              cluster='newCluster',
              task='d3a857b8f2e1463d85265e08b6dfd9f3',
              reason='none')
return response

  • Its Worth using the ARN for task and cluster and check how it works docs attached
  • This is how i have used it in my working code, reason being optional.(here i have just substituted the values for that variable here for explanation)
        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')
0
votes
import json
       import boto3

       client = boto3.client('ecs')

       def lambda_handler(event, context):
response=client.stop_task(cluster='newCluster',task='d3a857b8f2e1463d85265e08b6dfd9f3',reason='none')

I just removed the return and its braces and it worked.