Fazi
08/05/2021, 10:23 AMrequirements.txt
file for an example lambda function. However, I keep getting a module not found error for the dependencies I am trying to install (requests
)
My MyStack.js
file is as follows:
import * as sst from "@serverless-stack/resources";
export default class MyStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
// Create a HTTP API
const api = new sst.Api(this, "Api", {
defaultFunctionProps: {
srcPath: "src/example",
},
routes: {
"GET /": "lambda.handler",
}
});
// Show the endpoint in the output
this.addOutputs({
"ApiEndpoint": api.url,
});
}
}
My lambda.py
file:
import requests
def handler(event, context):
return {
"statusCode": 200,
"body": "Hello, World! Your request was received at {}.".format(
event["requestContext"]["time"]
),
}
My directory structure:thdxr
08/05/2021, 10:48 AMthdxr
08/05/2021, 10:48 AMSimon Reilly
08/05/2021, 10:51 AMFazi
08/05/2021, 10:52 AMindex.ts
file:
import MyStack from "./MyStack";
import * as sst from "@serverless-stack/resources";
export default function main(app: <http://sst.App|sst.App>): void {
// Set default runtime for all functions
app.setDefaultFunctionProps({
runtime: "python3.7"
});
new MyStack(app, "my-stack");
// Add more stacks
}
thdxr
08/05/2021, 10:53 AMFazi
08/05/2021, 10:54 AMimport requests
it all works nicely.
The error I get if I try and include the import:Fazi
08/05/2021, 10:54 AMrequirements.txt
file is not installedthdxr
08/05/2021, 10:58 AMthdxr
08/05/2021, 10:59 AMSimon Reilly
08/05/2021, 10:59 AMSimon Reilly
08/05/2021, 11:00 AMFazi
08/05/2021, 11:02 AMFazi
08/05/2021, 11:08 AMlambda.py
file is housed that contains the handler function? I guess I am unsure how SST will ensure that the lambda function has access to all the dependenciesthdxr
08/05/2021, 11:16 AMthdxr
08/05/2021, 11:16 AMFazi
08/05/2021, 11:19 AM