0
votes

I had invoked a lambda to stop some instances using python boto3 lambda invoke function. I am invoking the function with some payload. The invocation is successful but i do not see any log of execution in cloud watch. Basically seems the code execution did not start.

Code:

def stop_start_server():
    #sessions
    ec2c = boto3.client('lambda', region)
    instance_ids = {'Start_Stop': 'start', 'Instance_list': ['i-07fc5b6xxxx1584d', 'i-0da375xxxxxc2018b']}
    load = {"Start_Stop": "stop","Instance_list": instance_ids}
    print load
    #payload = json.loads(load)
    payload= bytes(json.dumps(load))
    #payload = str(load)
    print payload
    response = ec2c.invoke(FunctionName = lambdafunction , InvocationType = 'RequestRe
    print response
    payload = json.loads(response['Payload'].read())
    print payload

Output:

{
    u 'Payload': < botocore.response.StreamingBody object at 0x7fd8f9c31350 > , u 'ExecutedVersion': '$LATEST', 'ResponseMetadata': {
        'RetryAttempts': 0,
        'HTTPStatusCode': 200,
        'RequestId': 'efcaf7f4-5847-487f-921a-3e87657a7450',
        'HTTPHeaders': {
            'x-amzn-requestid': 'efcaf7f4-5847-487f-921a-3e87657a7450',
            'content-length': '2',
            'x-amz-executed-version': '$LATEST',
            'x-amzn-trace-id': 'root=1-5e9a06f7-3c4b263c83bb7989df2b596e;sampled=0',
            'x-amzn-remapped-content-length': '0',
            'connection': 'keep-alive',
            'date': 'Fri, 17 Apr 2020 19:43:55 GMT',
            'content-type': 'application/json'
        }
    }, u 'StatusCode': 200
}

what i see from cloud watch: enter image description here

seems like the function is triggered but the code execution did not happen. can some help me with what I ma missing

1
Hi, that's interesting... hmm I wonder if the logging library would help docs.aws.amazon.com/lambda/latest/dg/… - IronMan
Could you show your lambda handler? stop_start_server function does not seem to be your handler. - Marcin
To enable a Lambda function to send information to Amazon CloudWatch Logs, the IAM Role associated with the function should be given the AWSLambdaBasicExecutionRole policy. This policy includes permissions to write to CloudWatch Logs. See: AWS Lambda Execution Role - AWS Lambda - John Rotenstein
@Marcin the code which i gave is getting executed in my local and the function stop_start_server is calling the lambda function in AWS in turn. - varun
@JohnRotenstein the lambda role has the permission to AWS cloud watch. Otherwise we will not be able to see the trigger log from the cloudwatch. - varun

1 Answers

1
votes

The default timeout for a lambda is 3 seconds. Given the REPORT line you see in CloudWatch I bet you're hitting this. When timeout is reached, the lambda execution stops right away so you won't see anything in the logs except for this REPORT line.

You can change the timeout value in the admin console for your function.

Now this explains why you don't see anything in the logs, but you'll still need to investigate why this timeout is happening. Most likely there is a network timeout of some sort, caused by either a networking configuration problem or permission issue. There's not enough details in your question to help with this, but if it's networking, maybe you need to associate your lambda with your VPC.