-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ERROR] Runtime.ImportModuleError: Unable to import module #1963
Comments
SAM CLI will mount your CodeUri into the container. So the file structure on your host will not match what is in the container. In your case: files within src/sample/handler will live within /var/task on the container, which means src is not a valid module in lambda. Which gives you the error you are seeing. You will need to reconfigure your imports and your CodeUri to allow importing in Lambda's filesystems not your host. |
Closing this issue, since @jfuss has responded with the next steps. |
Fixed by :
├── README.md
├── __init__.py
├── create_handler.py
├── delete_handler.py
├── dynamodb_helper.py
├── environment.json
├── events
│ ├── create_event.json
│ └── get_event.json
├── get_handler.py
├── list_handler.py
├── logging_helper.py
├── packaged.yaml
├── requirements.txt
├── template.yaml
└── update_handler.py
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sample-app
SAM Template for service
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 20
MemorySize: 1024
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
TABLE_NAME: ""
DDB_ENDPOINT_OVERRIDE: ""
INTEGRATION_TESTS_ENDPOINT: ""
APPLICATION_NAME: ""
Resources:
CreateQuestionFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: .
Handler: create_handler.lambda_handler
Runtime: python3.7
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref QuestionsTable
Events:
CreateQuestion:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /sample
Method: post
GetQuestionFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: .
Handler: get_handler.lambda_handler
Runtime: python3.7
Policies:
- DynamoDBReadPolicy:
TableName: !Ref QuestionsTable
Events:
GetQuestion:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /sample/{sample_id}
Method: get
ListQuestionFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: .
Handler: list_handler.lambda_handler
Runtime: python3.7
Policies:
- DynamoDBReadPolicy:
TableName: !Ref QuestionsTable
Events:
GetQuestions:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /sample
Method: get
UpdateQuestionFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: .
Handler: update_handler.lambda_handler
Runtime: python3.7
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref QuestionsTable
Events:
UpdateQuestion:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /sample/{sample_id}
Method: post
DeleteQuestionFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: .
Handler: delete_handler.lambda_handler
Runtime: python3.7
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref QuestionsTable
Events:
DeleteQuestion:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /sample/{sample_id}
Method: delete
QuestionsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: sample
AttributeDefinitions:
- AttributeName: user_id
AttributeType: S
- AttributeName: _id
AttributeType: S
KeySchema:
- AttributeName: user_id
KeyType: HASH
- AttributeName: topic_id
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
Outputs:
CreateQuestionFunction:
Description: "CreateQuestion Lambda Function ARN"
Value: !GetAtt CreateQuestionFunction.Arn
GetQuestionFunction:
Description: "GetQuestion Lambda Function ARN"
Value: !GetAtt GetQuestionFunction.Arn
ListQuestionFunction:
Description: "GetQuestions Lambda Function ARN"
Value: !GetAtt ListQuestionFunction.Arn
UpdateQuestionFunction:
Description: "UpdateQuestion Lambda Function ARN"
Value: !GetAtt UpdateQuestionFunction.Arn
DeleteQuestionFunction:
Description: "DeleteQuestion Lambda Function ARN"
Value: !GetAtt DeleteQuestionFunction.Arn
don't like the fix for :
|
+1 for not being able to create packages. |
you don't need to add all your lambdas into one directory. See aws-samples/aws-serverless-samfarm#5 (comment) |
As mentioned in a issue I submitted to aws/aws-cli#6615, I am struggling to configure the docker build that occurs when running the I am not sure if the restructuring of the AWS SAM template will solve the issue of needing to install many dependencies in the container being used. This was complicated enough when doing local testing using If anyone could provide insight into how to set up local testing of stepfunctions with multiple lambda functions with various modules and dependencies? The current structure that is used for local functional testing with
This works correctly just using I have multiple of these Lambda functions, each composing a portion of a step function defined in a Is it possible to use the If this is too off-topic for this issue I am happy to open a new issue, I was directed here as the build process seems to be from the SAM CLI but the stepfunctions portion of the workflow if from the AWS CLI, please advise! Thanks :) |
I now realize that there is a conflict between my utils in my other layer and the utils in this repository, any suggestions for a fix? |
sam issue
Hello SAM - LAMBDA users,
On running :
sam local start-api --env-vars test/sample/integration_test/environment.json
and
Getting below error
This is my project structure
This is my
template.yaml
Also my docker doesnt show sam-app
sam --version
: SAM CLI, version 0.48.0The text was updated successfully, but these errors were encountered: