Reputation: 13
I have an AWS lambda function to trigger daily importer jobs
I am using a "A starter AWS Lambda function." for this and the lambda_handler is quite simple. This is a pseudo code of what I am doing:
try:
cron_job = CloudCron()
status = redis_get_importer_status(db_key, key)
if status != 'running':
cron_job.login()
redis_set_importer_status(db_key, key, 'running')
cron_job.start_importer()
except Exception:
exc_traceback = traceback.print_exc()
print(exc_traceback)
This function is triggered by a CloudWatch Event every 15 minutes.
The lambda function failed to run the lambda_handler and complained about not having an execution policy for the VPC. To resolve this issue, I attached AWSLambdaVPCAccessExecutionRole Policy for this role. While this ran my lamda_handler, there were other issues. The python requests module threw a ConnectionError when trying to login to the site. I increased the timeout to 5 minutes and memory to 1GB and still seeing this issue.
ConnectionError: HTTPSConnectionPool(host='test.site.com.au', port=443): Max retries exceeded with url: /auth/login (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 110] Connection timed out',))
I ran the same lambda_handler within my VPC and seems to be working seamlessly.
I finally removed the redis set status and get status in my lambda function and the VPC configuration in the lamba and ran the lamda_handler again and this seems to work without any issues.
I need the VPC configuration to set and get keys from the redis server.
Any help is appreciated!
Cheers!
Upvotes: 1
Views: 5286
Reputation: 200998
Once you place the Lambda function inside your VPC it can only access resources inside the VPC. It can't connect to test.site.com.au
because that resolves to a public IP address outside your VPC. You have a few options to get around this issue:
Upvotes: 3