简体   繁体   English

AWS Lambda函数日志未在CloudWatch中显示

[英]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. 我有一个在我的Linux主机上本地运行的python应用程序。 I am using boto3 to connect to AWS with my user secret key and secret key Id. 我正在使用boto3通过用户密钥和密钥ID连接到AWS。 My user had full access to EC2, Cloudwatch, S3 and config 我的用户拥有对EC2,Cloudwatch,S3和配置的完全访问权限

My application invokes a lamdbda function called mylambda. 我的应用程序调用了一个名为mylambda的lamdbda函数。 The execution role for mylambda also has all the required permissions. mylambda的执行角色还具有所有必需的权限。

Now if i call my lambda function from aws console it works fine. 现在,如果我从aws控制台调用lambda函数,则可以正常工作。 I can see the logs of execution in cloudwatch. 我可以在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. 但是,如果我从自定义应用程序的linux框中执行此操作,则看不到任何执行日志,我也不会收到错误。

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。 Lambda error handling can be a bit tricky. Lambda错误处理可能会有些棘手。 Using boto3 the invoke method doesn't necessarily throw even if the invocation fails. 使用boto3,即使调用失败,invoke方法也不一定会抛出。 You have to check the statusCode property in the response. 您必须检查响应中的statusCode属性。

You mentioned that your user has full access to EC2, Cloudwatch, S3, and config. 您提到用户拥有对EC2,Cloudwatch,S3和config的完全访问权限。 For your use case, you need to add lambda:InvokeFunction to your user's permissions. 对于您的用例,您需要将lambda:InvokeFunction添加到用户的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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