Questions tagged with AWS Lambda

Content language: English

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

I am trying to list the databases in my DocumentDb from a Lambda function, and the task times out. It is a simple command it should not be timing out. What do I need to fix so that the command runs properly? ``` client = MongoClient(connectionString) logging.info("All the databases") logging.info(client.list_database_names()) ``` When I run the code on my VS Code IDE I get this message; > Exception has occurred: ServerSelectionTimeoutError docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017: [Errno 11001] getaddrinfo failed, Timeout: 30s, Topology Description: <TopologyDescription id: 641e0297b555a6d973f82353, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017: [Errno 11001] getaddrinfo failed')>]> File "C:\mma\Lambda_tweets\lambda_handler.py", line 47, in getDBConnection logging.info(client.list_database_names()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\mma\Lambda_tweets\lambda_handler.py", line 127, in lambda_handler getDBConnection() File "C:\mma\Lambda_tweets\lambda_handler.py", line 130, in <module> lambda_handler(None, None) pymongo.errors.ServerSelectionTimeoutError: docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017: [Errno 11001] getaddrinfo failed, Timeout: 30s, Topology Description: <TopologyDescription id: 641e0297b555a6d973f82353, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017: [Errno 11001] getaddrinfo failed')>]> EDIT: When I extended the timeout as suggested in the comments, the error messages I was getting were as follows; > Response { "errorMessage": "docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: <TopologyDescription id: 641f88d7e7919b310a30cf51, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017: [Errno -2] Name or service not known')>]>", "errorType": "ServerSelectionTimeoutError", "requestId": "2f9fb04f-9519-41e9-b989-0dd8b6f3382b", "stackTrace": [ " File \"/var/task/lambda_function.py\", line 62, in lambda_handler\n getDBConnection()\n", " File \"/var/task/lambda_function.py\", line 51, in getDBConnection\n logging.info(client.list_database_names())\n", " File \"/opt/python/pymongo/mongo_client.py\", line 1867, in list_database_names\n return [doc[\"name\"] for doc in self.list_databases(session, nameOnly=True, comment=comment)]\n", " File \"/opt/python/pymongo/mongo_client.py\", line 1840, in list_databases\n res = admin._retryable_read_command(cmd, session=session)\n", " File \"/opt/python/pymongo/database.py\", line 849, in _retryable_read_command\n return self.__client._retryable_read(_cmd, read_preference, session)\n", " File \"/opt/python/pymongo/_csot.py\", line 105, in csot_wrapper\n return func(self, *args, **kwargs)\n", " File \"/opt/python/pymongo/mongo_client.py\", line 1441, in _retryable_read\n server = self._select_server(read_pref, session, address=address)\n", " File \"/opt/python/pymongo/mongo_client.py\", line 1257, in _select_server\n server = topology.select_server(server_selector)\n", " File \"/opt/python/pymongo/topology.py\", line 272, in select_server\n server = self._select_server(selector, server_selection_timeout, address)\n", " File \"/opt/python/pymongo/topology.py\", line 261, in _select_server\n servers = self.select_servers(selector, server_selection_timeout, address)\n", " File \"/opt/python/pymongo/topology.py\", line 223, in select_servers\n server_descriptions = self._select_servers_loop(selector, server_timeout, address)\n", " File \"/opt/python/pymongo/topology.py\", line 238, in _select_servers_loop\n raise ServerSelectionTimeoutError(\n" ] } > Function Logs START RequestId: 2f9fb04f-9519-41e9-b989-0dd8b6f3382b Version: $LATEST [INFO] 2023-03-25T23:50:47.126Z 2f9fb04f-9519-41e9-b989-0dd8b6f3382b get client /opt/python/pymongo/common.py:813: UserWarning: Unknown option ssl_ca_certs warnings.warn(str(exc)) [INFO] 2023-03-25T23:50:47.380Z 2f9fb04f-9519-41e9-b989-0dd8b6f3382b Get database testdb [INFO] 2023-03-25T23:50:47.380Z 2f9fb04f-9519-41e9-b989-0dd8b6f3382b All the databases [ERROR] ServerSelectionTimeoutError: docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: <TopologyDescription id: 641f88d7e7919b310a30cf51, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017: [Errno -2] Name or service not known')>]> Traceback (most recent call last):   File "/var/task/lambda_function.py", line 62, in lambda_handler     getDBConnection()   File "/var/task/lambda_function.py", line 51, in getDBConnection     logging.info(client.list_database_names())   File "/opt/python/pymongo/mongo_client.py", line 1867, in list_database_names     return [doc["name"] for doc in self.list_databases(session, nameOnly=True, comment=comment)]   File "/opt/python/pymongo/mongo_client.py", line 1840, in list_databases     res = admin._retryable_read_command(cmd, session=session)   File "/opt/python/pymongo/database.py", line 849, in _retryable_read_command     return self.__client._retryable_read(_cmd, read_preference, session)   File "/opt/python/pymongo/_csot.py", line 105, in csot_wrapper     return func(self, *args, **kwargs)   File "/opt/python/pymongo/mongo_client.py", line 1441, in _retryable_read     server = self._select_server(read_pref, session, address=address)   File "/opt/python/pymongo/mongo_client.py", line 1257, in _select_server     server = topology.select_server(server_selector)   File "/opt/python/pymongo/topology.py", line 272, in select_server     server = self._select_server(selector, server_selection_timeout, address)   File "/opt/python/pymongo/topology.py", line 261, in _select_server     servers = self.select_servers(selector, server_selection_timeout, address)   File "/opt/python/pymongo/topology.py", line 223, in select_servers     server_descriptions = self._select_servers_loop(selector, server_timeout, address)   File "/opt/python/pymongo/topology.py", line 238, in _select_servers_loop     raise ServerSelectionTimeoutError(END RequestId: 2f9fb04f-9519-41e9-b989-0dd8b6f3382b REPORT RequestId: 2f9fb04f-9519-41e9-b989-0dd8b6f3382b Duration: 30494.77 ms Billed Duration: 30495 ms Memory Size: 128 MB Max Memory Used: 66 MB Init Duration: 555.69 ms
1
answers
0
votes
21
views
asked a day ago
I develop a NET 6 Web REST API service (->RDS PostgreSQL) deployed as Lambda. I develop it in VS 2022 on Local Windows machine and use local PGSQL. When deploy it to Lambda it works with RDS. It is ok. Now I need to add Authentication and Authorization methods to use RBAC. My question is: In AWS I should use Cognito Identity Provider. What to use during development as Cognito in local environment?
0
answers
0
votes
9
views
Oleg
asked a day ago
I am trying to get a list of database names for my DocumentDB. I am using the pymongo library. I run this code; ``` logging.info("get client") #connectionString = os.environ["documentdb_connection"] connectionString = "mongodb://geoff:qzmpqzmp@docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false" ##Specify the database to be used logging.info("Get database testdb") #db = client.testdb logging.info("All the databases") #db = client.testdb logging.info(client.list_database_names()) ``` I have been unable to connect to the specific database I wanted so I thought I would comment those lines out and instead list all of the databases to check if it exists. On the last line of that code I get a NameError; "name 'client' is not defined" How do I fix this?
1
answers
0
votes
16
views
asked a day ago
I want to access DocumentDb in my Lambda function. I try to configure my VPC in the Edit VPC page for my lambda function but I get this error message that stops me; > The provided execution role does not have permissions to call CreateNetworkInterface on EC2 How do I fix this?
Accepted AnswerAmazon VPCAWS Lambda
1
answers
0
votes
13
views
asked a day ago
Hi, I am deploying a lambda function that utilizes the NLTK packages for preprocessing text. For the application to work I need to download the stop words, punkt and wordnet libraries. I have deployed using a docker image and SAM cli. When the function runs on AWS, I get a series of errors when trying to access the NLTK libraries. The first error I got was that '/home/sbx_user1051/' cannot be edited. After reading solutions on stack over flow, I was pointed in the direction of needing to store the NLTK libraries in the /tmp/ directory because that is the only directory that can be modified. Now, after redeploying the image with the changes to the code, I have the files stored in temp, but the lambda function does not search for that file when trying to access the stop words. It still tries to search for the file in these directories: - '/home/sbx_user1051/nltk_data' - '/var/lang/nltk_data' - '/var/lang/share/nltk_data' - '/var/lang/lib/nltk_data' - '/usr/share/nltk_data' - '/usr/local/share/nltk_data' - '/usr/lib/nltk_data' - '/usr/local/lib/nltk_data' What should I do about importing the NLTK libraries needed when running this function on aws lambda?
0
answers
0
votes
11
views
Tyler
asked a day ago
I am currently working on a lambda function in which I have to send a message to an SQS queue. The Lambda function sits inside of a VPC to allow connection with a peered network that the Function makes requests to. Whenever I try to send the message to SQS however code execution seems to timeout consistently. I had the same issue when I was trying to send commands to DynamoDB. ``` import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs"; const sqsClient = new SQSClient({region: 'us-east-1'}); export const handler = async (event, context, callback) => { const response = await sqsClient.send(new SendMessageCommand(messageParams)); console.log(response); // <----- Doesn't reach here return callback(null, 'OK'); }; ``` IAM Permissions are all correct and the Security Group allows all traffic (When set to a VPC) So far, to specifically target the timeout problem, I've tried putting the function in a private subnet, public subnet, placing it in no VPC, replacing SDK v3 with aws-sdk v2 via a layer. None of these seem to have any impact on the issue. I haven't used VPC endpoints yet but I guess that shouldn't be necessary when the function is not connected to a VPC or in a public subnet?
0
answers
0
votes
12
views
asked 2 days ago
Hello, I store data in S3 as part of Amazon Data Exchange Products. I want to create an API product so that users can pull my data in csv or json format directly from the bucket. The bucket contains multiple csv's per day Do I need a lambda fronting an api in api gateway which will read the contents of the file first? Or, can I simply create an API which will parse the files and return data to the subscribers? I would then package that API up into a "data product" Ideally the data would be pulled as json by default, but they would also be able to pull it as csv. I will need to be able to give users the ability to structure a payload via SDK or CLI or some other IDE in which they specify various fields, date ranges etc... Thank you.
0
answers
0
votes
17
views
asked 2 days ago
So I have a lambda function that's the following: def lambda_handler(event, context): http = urllib3.PoolManager() return { "statusCode": 200, "headers": { "Content-Type": "application/json" }, "body": "{\"message\": \"Hello from Lambda!\"}", "test": event } If I test run the event with some event JSON, it returns what I want. But... when I test to run the lambda through my rest API I created I either get the error 502 when "Use Lambda Proxy integration" is enabled. Or when it's disabled event is always empty. I have tried to setup a link the following way: https://something.execute-api.eu-north-1.amazonaws.com/test/test/{id} Where you enter an {id} for example and I can catch it in the event. But how can I fix so event is an actual thing and actually getting any information? If you feel like im missing some information that might be important just ask, I don't know what could be useful.
0
answers
0
votes
18
views
asked 2 days ago
Hi there, I am trying to do some experiments to migrate from the data pipeline to the step function. I call the step function from the lambda function by passing a couple of parameters (name, env). My question is, how do I pass these parameters and clusterID (from the emr) to all next steps and use it? Also, is it possible to change the name of the cluster to the parameter I passed from the lambda function? Like "Parameters": {         "Name": "$.name",....? Please see the attached picture. ![sample step function](/media/postImages/original/IM_cL-uMn4Rx2NFKLzLAhlCg)
1
answers
0
votes
30
views
asked 2 days ago
Hello All, I've been trying to setup a Multi-region access point for S3. The basic problem is that I have users in Asia that I'm trying to get better performance for. The simple part. I've created two buckets, I've put an html file in each of them with a simple name of us-east-1 and ap-south-1. Initially those were private access only but for the purpose of getting anything working they are now public. They are setup in an mrap which for now is not replicating. I setup a cloudfront distribution and pointed it at the mrap but only ever get errors. https://corridor-ap-south-1.s3.ap-south-1.amazonaws.com/test/region-test/region.html - ap-south-1 html https://corridor-cdn.s3.amazonaws.com/test/region-test/region.html - us-east-1 html mrap alias: mbzcc59bo9dy4.mrap mrap access point? https://mbzcc59bo9dy4.mrap.accesspoint.s3-global.amazonaws.com/test/region-test/region.html The errors are: The authorization mechanism you have provided is not supported. Please use Signature Version 4. I hope I'm wrong, but is there a ridiculously stupid world where I have to put a signature on my object request? This seems like it would be a complete waste of money to setup a lambda to do this for all my object requests.
0
answers
0
votes
11
views
asked 3 days ago
The following link is helpful in answering how to unblock port 25: [Remove port 25 restriction from your EC2 instance | AWS re:Post](https://repost.aws/knowledge-center/ec2-port-25-throttle). However, my question pertains as to why it's blocked. Doing some research I've found a list of reasons as to why port 25 might be blocked or throttled by hosts and ISPs, but I was hoping for a more official explanation from AWS as to why it's blocked here. Thank you.
2
answers
0
votes
22
views
asked 3 days ago
I want to send data to s3 bucket using extensions that we add in layers. at aws lambda.
2
answers
0
votes
11
views
asked 3 days ago