AWS Lambda Layer not Working

0

I have written a lambda function that uses requests module of python. The problem is requests isn't a standard library and hence not included anymore in AWS SDK for post runtime 3.7. Recently they also removed the option to use runtime 3.7 in lambda.

So I created lambda layer and added a zip file containing the requests module. And then added that layer to my Lambda Function. Also increased lambda function timeout ( checked all possibilities between 10 sec - 180 sec). Still my lambda function is failing with below error :

Response { "errorMessage": "2024-01-22T03:40:50.680Z b16511d8-2e35-4ce6-b065-d30336090372 Task timed out after 10.01 seconds" }

Function Logs START RequestId: b16511d8-2e35-4ce6-b065-d30336090372 Version: $LATEST 2024-01-22T03:40:50.680Z b16511d8-2e35-4ce6-b065-d30336090372 Task timed out after 10.01 seconds

END RequestId: b16511d8-2e35-4ce6-b065-d30336090372 REPORT RequestId: b16511d8-2e35-4ce6-b065-d30336090372 Duration: 10012.62 ms Billed Duration: 10000 ms Memory Size: 128 MB Max Memory Used: 18 MB

I have used below guide to create lambda layer : https://cloudbennett.com/5-steps-for-adding-requests-module-to-aws-lambda-python-functions-590ac40c54e7

Also directly created lambda layer from using aws cli instead of storing it in S3 bucket.

Please can someone help me resolve this issue.

If you want to checkout, my lambda function code is written below :

import json import requests #from botocore.vendored import requests

def lambda_handler(event, context): # TODO implement jenkins_url = "http://172.31.41.225:8080" username = "sarbajit" token = "11bdaff7fedeaa457bb5613aef796a25ae" job_name = "IPCC-Asterisk-Configuration"

auth = requests.auth.HTTPBasicAuth(username, token)
build_url = f"{jenkins_url}/job/{job_name}/build?token={token}"

response = requests.post(build_url, auth=auth)

if response.status_code == 201:
    print("Jenkins job triggered successfully!")
else:
    print("Failed to trigger Jenkins job. Response:", response.text)

return {
    'statusCode': 200,
    'body': 'Jenkins job trigger attempt complete'
}

P.S. : The code is executing fine with another lambda function having python 3.7 runtime. But I can't create any more of such functions as runtime 3.7 is no longer available to be used for any new lambda Function. I have create the infra in a different AWS Region and thus i need help to resolve this issue. Please Help.

Sarba
質問済み 4ヶ月前312ビュー
1回答
1
承認された回答

Hello.

Looking at the code, it looks like it is accessing "172.31.41.225", but is this an IP address such as EC2 within the VPC?
In that case, you need to connect Lambda to your VPC using the steps in the documentation below.
https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html#vpc-configuring

Also, be sure to set up inbound rules to allow traffic from Lambda in the security group you connect to, such as EC2.

profile picture
エキスパート
回答済み 4ヶ月前
profile picture
エキスパート
レビュー済み 1ヶ月前
  • Thanks for the response Mr. Riku Kobayashi. After connecting VPC to Lambda Function issue got resolved.

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ