Nicklas Nyegaard
10/05/2021, 2:14 PM[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'src' Traceback (most recent call last):
but when I run in debug mode I am able to hit the lambdaDan Van Brunt
10/05/2021, 2:15 PMNicklas Nyegaard
10/05/2021, 2:16 PMimport * as sst from "@serverless-stack/resources";
import { TableFieldType } from "@serverless-stack/resources";
import { LayerVersion } from "@aws-cdk/aws-lambda";
import * as ssm from "@aws-cdk/aws-ssm";
export default class IntegrationSalesforceProvivienda extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
const integrationName = `${this.stage}-integrations-salesforce-provivienda-sst`;
new ssm.StringParameter(
this,
"integrations-salesforce-provivienda-accesstoken-parameter",
{
allowedPattern: ".*",
description:
"Access token for production environment to access SF REST API",
parameterName: `provivienda_salesforce_access_token_${this.stage}`,
stringValue: " ",
}
);
new ssm.StringParameter(
this,
"integrations-salesforce-provivienda-consumerkey-parameter",
{
allowedPattern: ".*",
description: "Consumer public key to identify external application",
parameterName: `provivienda_salesforce_consumer_key_${this.stage}`,
stringValue: " ",
}
);
new ssm.StringParameter(
this,
"integrations-salesforce-provivienda-instanceurl-parameter",
{
allowedPattern: ".*",
description: "Instance url of provivienda salesforce organization",
parameterName: `provivienda_salesforce_instance_url_${this.stage}`,
stringValue: " ",
}
);
new ssm.StringParameter(
this,
"integrations-salesforce-provivienda-password-parameter",
{
allowedPattern: ".*",
description: "Resource owner password",
parameterName: `provivienda_salesforce_password_${this.stage}`,
stringValue: " ",
}
);
new ssm.StringParameter(
this,
"integrations-salesforce-provivienda-username-parameter",
{
allowedPattern: ".*",
description: "Resource owner username",
parameterName: `provivienda_salesforce_username_${this.stage}`,
stringValue: " ",
}
);
new ssm.StringParameter(
this,
"integrations-salesforce-provivienda-securitytoken-parameter",
{
allowedPattern: ".*",
description: "Resource owner security token",
parameterName: `provivienda_salesforce_security_token_${this.stage}`,
stringValue: " ",
}
);
const table = new sst.Table(this, `Table`, {
fields: {
eomu: TableFieldType.STRING,
activity_code: TableFieldType.STRING,
retry_count: TableFieldType.NUMBER,
},
primaryIndex: { partitionKey: "eomu", sortKey: "activity_code" },
});
const layerArn = "arn:aws:lambda:eu-west-1:836484966858:layer:requests:4";
const layer = LayerVersion.fromLayerVersionArn(
this,
`${integrationName}-Layer`,
layerArn
);
// Create a HTTP API
const api = new sst.Api(this, `Api`, {
defaultFunctionProps: {
srcPath: "src",
logRetention: 14,
environment: {
SERVICE_NAME: `${this.stage}-integrations-salesforce-provivienda-sst`,
DYNAMODB_TABLE_NAME: table.dynamodbTable.tableName,
ACCESS_TOKEN_URL:
this.stage === "prod"
? "<https://login.salesforce.com/services/oauth2/token>"
: "<https://test.salesforce.com/services/oauth2/token>",
QUERY_SERVICE: "/services/data/v51.0/query/Product2/",
UPDATE_SERVICE:
"/services/data/v51.0/sobjects/Product2/vuu_codigo_unico__c/",
STAGE: `${scope.stageName}`,
},
},
routes: {
"GET /test": {
function: {
handler: "lambda_function.lambda_handler",
timeout: 29,
layers: [layer],
},
},
"POST /activity": {
function: {
handler: "lambda_function.lambda_handler",
timeout: 29,
layers: [layer],
},
},
},
customDomain: {
hostedZone: "<http://api.integrations.letsbuild.com|api.integrations.letsbuild.com>",
domainName: `${this.stage}-<http://proviviendasf.api.integrations.letsbuild.com|proviviendasf.api.integrations.letsbuild.com>`,
},
});
api.attachPermissions([table, "ssm"]);
// Show the endpoint in the output
this.addOutputs({
ApiEndpoint: api.url,
CustomDomain: api.customDomainUrl || "No custom domain is created",
});
}
}
Nicklas Nyegaard
10/05/2021, 2:17 PMDan Van Brunt
10/05/2021, 2:19 PMNicklas Nyegaard
10/05/2021, 2:20 PMDan Van Brunt
10/05/2021, 2:21 PMUnable to import module 'lambda_function'
sounds to me like the function itself is trying to load the module called ``lambda_function`` .
Are you using node? Can you share the imports at the top of lambda_function.lambda_handler
and what your function is called in thereNicklas Nyegaard
10/05/2021, 2:22 PMDan Van Brunt
10/05/2021, 2:23 PMNicklas Nyegaard
10/05/2021, 2:23 PMDan Van Brunt
10/05/2021, 2:23 PMDan Van Brunt
10/05/2021, 2:23 PMsst deploy
?Nicklas Nyegaard
10/05/2021, 2:24 PMDan Van Brunt
10/05/2021, 2:25 PMNo module named 'src'
is referring to? I assume you have all your function code sitting in directory /src
?Dan Van Brunt
10/05/2021, 2:25 PMNicklas Nyegaard
10/05/2021, 2:25 PMnpx sst start
and there it works
but when I try it with npx sst deploy --stage dev
I get Internal server error
with the logs as I describedDan Van Brunt
10/05/2021, 2:25 PMhandler: 'src/lambda.webhook',
Nicklas Nyegaard
10/05/2021, 2:26 PMDan Van Brunt
10/05/2021, 2:27 PMsrcPath: "src",
so that should be fine?Dan Van Brunt
10/05/2021, 2:27 PMNicklas Nyegaard
10/05/2021, 2:27 PMDan Van Brunt
10/05/2021, 2:27 PMsrcPath: "src",
but adding it locally as you wereNicklas Nyegaard
10/05/2021, 2:28 PMDan Van Brunt
10/05/2021, 2:28 PMNicklas Nyegaard
10/05/2021, 2:28 PMNicklas Nyegaard
10/05/2021, 2:28 PMthdxr
10/05/2021, 2:28 PMNicklas Nyegaard
10/05/2021, 2:29 PMError: Cannot set the "srcPath" to the project root for the "Lambda_GET_/test" function.
Dan Van Brunt
10/05/2021, 2:29 PMDan Van Brunt
10/05/2021, 2:29 PMNo module named 'src'
is the part that seems odd to meNicklas Nyegaard
10/05/2021, 2:29 PMFor Python functions, srcPath is required. This is the directory where the requirements.txt, Pipfile, or poetry.lock is expected.
Nicklas Nyegaard
10/05/2021, 2:30 PMNicklas Nyegaard
10/05/2021, 2:30 PMDan Van Brunt
10/05/2021, 2:31 PMDan Van Brunt
10/05/2021, 2:32 PMNicklas Nyegaard
10/05/2021, 2:32 PMNicklas Nyegaard
10/05/2021, 2:32 PMNicklas Nyegaard
10/05/2021, 2:32 PMDan Van Brunt
10/05/2021, 2:32 PMDan Van Brunt
10/05/2021, 2:33 PMNicklas Nyegaard
10/05/2021, 2:33 PMDan Van Brunt
10/05/2021, 2:35 PMthdxr
10/05/2021, 2:43 PMthdxr
10/05/2021, 2:44 PMsrcPath
thdxr
10/05/2021, 2:44 PMNicklas Nyegaard
10/05/2021, 2:45 PMNicklas Nyegaard
10/05/2021, 2:46 PMthdxr
10/05/2021, 2:46 PMthdxr
10/05/2021, 2:47 PMNicklas Nyegaard
10/05/2021, 2:48 PMNicklas Nyegaard
10/05/2021, 2:49 PMthdxr
10/05/2021, 2:49 PMthdxr
10/05/2021, 2:49 PM"GET /": "handler"
Nicklas Nyegaard
10/05/2021, 2:52 PMconst api = new sst.Api(this, `Api`, {
defaultFunctionProps: {
srcPath: "src",
logRetention: 14,
timeout: 29,
layers: [layer],
environment: {
SERVICE_NAME: `${this.stage}-integrations-salesforce-provivienda-sst`,
DYNAMODB_TABLE_NAME: table.dynamodbTable.tableName,
ACCESS_TOKEN_URL:
this.stage === "prod"
? "<https://login.salesforce.com/services/oauth2/token>"
: "<https://test.salesforce.com/services/oauth2/token>",
QUERY_SERVICE: "/services/data/v51.0/query/Product2/",
UPDATE_SERVICE:
"/services/data/v51.0/sobjects/Product2/vuu_codigo_unico__c/",
STAGE: `${scope.stageName}`,
},
},
routes: {
"GET /test": "lambda_function.lambda_handler",
"POST /activity": "lambda_function.lambda_handler",
},
customDomain: {
hostedZone: "<http://api.integrations.letsbuild.com|api.integrations.letsbuild.com>",
domainName: `${this.stage}-<http://proviviendasf.api.integrations.letsbuild.com|proviviendasf.api.integrations.letsbuild.com>`,
},
});
thdxr
10/05/2021, 2:53 PMsrc
thdxr
10/05/2021, 2:53 PMNicklas Nyegaard
10/05/2021, 2:54 PMNicklas Nyegaard
10/05/2021, 2:54 PMNicklas Nyegaard
10/05/2021, 2:54 PM/
to the end of srcPath?Nicklas Nyegaard
10/05/2021, 2:58 PM[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'src' Traceback (most recent call last):
thdxr
10/05/2021, 2:59 PM/
doesn't matter. Ok I think I need @Frank to chime in here, I can't remember the right way to do python importsNicklas Nyegaard
10/05/2021, 3:01 PMNicklas Nyegaard
10/05/2021, 3:01 PMNicklas Nyegaard
10/05/2021, 6:42 PMFrank
lambda_function.py
file at the root? And if you scroll down a bit on the page, can you check what the handler for this Lambda function is set to?Nicklas Nyegaard
10/12/2021, 7:34 AM