aws_requests_auth problem

0

I'm trying to create an apigateway in order to create an api that integrates the lex bot. I did that using sam with lambda function;the probelm when I run locally my script using sam local start-api I got this :

Invalid lambda response received: Invalid API Gateway Response Keys: {'requestId', 'errorMessage', 'errorType', 'stackTrace'} in {'errorMessage': "Unable to import module 'app': No module named 'aws_requests_auth'", 'errorType': 'Runtime.ImportModuleError', 'requestId': 'XXXXXX', 'stackTrace': []} although I already installed aws_requests_auth lib and the api is working fine on postman.

I check the installation using pip list command and I got this : aws-requests-auth 0.4.3

this is the script :

import json import boto3 import os import uuid import requests from aws_requests_auth.aws_auth import AWSRequestsAuth

def run(event,context): URL = apiURL"

payload="{\r\n\r\n   \"text\": \"2012\"\r\n}"
#### put the  api-key found in the lapose.fr api documentation https://developer.laposte.fr/ 
headers = {

'Content-Type': 'application/json', 'X-Amz-Content-Sha256': 'XXXXXXXXX', 'X-Amz-Date': 'XXXXXXXXXXXX' } auth = AWSRequestsAuth( aws_access_key='XXXXXXXXXXX', aws_secret_access_key='XXXXXXXXXX', aws_host='runtime-v2-lex.us-east-1.amazonaws.com', aws_region='us-east-1', aws_service='lex' )

response = requests.post(URL, headers=headers, data=payload ,auth=auth)
print(response.json())


return{
  'statusCode':200,
  'headers': {
    'Content-Type': 'application/json',
    },
    'body': json.dumps(response.json())
    }
1 Answer
0

The sam build command uses the python requirements.txt file to install the required packages in the container image or zip file. Your error implies that aws_requests_auth is not included in the requirements.txt file. In fact, I got the exact same error when I replicated your code and did not include that package in the requirements.txt file.

How to resolve:

  1. requirements.txt should already exist in your app folder, if not, create it.
  2. Add any required packages to that file
  3. Rebuild the application by executing sam build
  4. Run the api locally with sam local start-api

Here is a quick screenshot of my project: Image of requirements.txt

profile pictureAWS
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions