简体   繁体   中英

AWS lambda function logs are not getting displayed in cloudwatch

I have below setup which I am trying to run.

I have a python app which is running locally on my linux host. I am using boto3 to connect to AWS with my user secret key and secret key Id. My user had full access to EC2, Cloudwatch, S3 and config

My application invokes a lamdbda function called mylambda. The execution role for mylambda also has all the required permissions.

Now if i call my lambda function from aws console it works fine. I can see the logs of execution in cloudwatch. But if I do it from my linux box from my custom application, I dont see any execution logs, I am not getting error either.

is there anything I am missing ?

Any help is really appreciated.

I dont see it getting invoked. But surprisingly I am getting response as below.

gaurav@random:~/lambda_s3$ python main.py {u'Payload': <botocore.response.StreamingBody object at 0x7f74cb7f5550>, u'ExecutedVersion': '$LATEST', 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '7417534c-6263-11e8-xxx-afab1667510a', 'HTTPHeaders': {'x-amzn-requestid': '7417534c-xxx-11e8-8a24-afab1667510a', 'content-length': '4', 'x-amz-executed-version': '$LATEST', 'x-amzn-trace-id': 'root=1-5b0bdc78-7559e68acd668476bxxxx754;sampled=0', 'x-amzn-remapped-content-length': '0', 'connection': 'keep-alive', 'date': 'Mon, 28 May 2018 10:39:52 GMT', 'content-type': 'application/json'}}, u'StatusCode': 200} {u'CreationDate': datetime.datetime(2018, 5, 27, 9, 50, 9, tzinfo=tzutc()), u'Name': 'bucketname'} gaurav@random:~/lambda_s3$

My sample app is as below

#!/usr/bin/python
import boto3
import json
import base64
d= {'key': 10, 'key2' : 20}
client = boto3.client('lambda')

response = client.invoke(
    FunctionName='mylambda',
    InvocationType='RequestResponse',
    #LogType='None',
    ClientContext=base64.b64encode(b'{"custom":{"foo":"bar", \
                            "fuzzy":"wuzzy"}}').decode('utf-8'),
    Payload=json.dumps(d)
)
print response

Make sure that you're actually invoking the Lambda correctly. Lambda error handling can be a bit tricky. Using boto3 the invoke method doesn't necessarily throw even if the invocation fails. You have to check the statusCode property in the response.

You mentioned that your user has full access to EC2, Cloudwatch, S3, and config. For your use case, you need to add lambda:InvokeFunction to your user's permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM