varun
varun

Reputation: 11

AWS lambda not running the code when invoked

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

Upvotes: 0

Views: 2243

Answers (1)

Jules Oll&#233;on
Jules Oll&#233;on

Reputation: 6888

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.

Upvotes: 1

Related Questions