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
defineService is undefined #1080
Comments
same, I downgraded to 6.5.0 works perfectly, but with 6.7.0 nope. |
I have downgraded to 6.5.0 and still seeing the error "devDependencies": {
|
Did you clean node_modules and build it again after downgrade? Edit: |
Nope even with the rm -rf node_modules its failing with the same error. (initial request succeeds, consecutive ones fail)
My dependencies: "dependencies": { My health endpoint:
|
Can confirm I get it as well on 6.5.0. Haven't noticed the issue before today. |
any resolution to this? I am also facing this all of a sudden. @6.5.0 |
Resolved the issue by adding
Upgraded back to 6.7.0 |
Thank you for your advice. Where did you add this exactly? |
In serverless.yaml service: ...
custom:
serverless-offline:
useChildProcesses: true
And thanks for that advice, worked great! |
Thanks ! This was already driving me nuts. From the error It seemed like it was related to aws-sdk not being able to auth... |
Solved my issue as well, thanks |
Had a similar issue using pino logger (pino-http/express-pino-logger) where without the |
From aws-sdk, the code in question:
Appears that the core AWS module is being compromised at some point. |
FYI, earlier closed issue points to using allowCache to avoid error: #1075 (comment) |
BTW, I think package.json for 6.5.0 is |
Encountered this issue today using, Both suggested fixes are working but custom:
serverless-offline:
useChildProcesses: true # ~300ms
allowCache: true # ~100ms |
The script from @cchamplin also fix it, no need to use useChildProcesses or allowCache. Look at theses 2 comments |
|
If you do not want to add |
I am also having this issue; I have a lambda function with an API Gateway that reads from S3. "dependencies": {
"aws-sdk": "^2.783.0",
"firebase-admin": "^8.11.0",
"serverless-offline-scheduler": "^0.4.2",
"serverless-pseudo-parameters": "^2.5.0",
"source-map-support": "^0.5.10"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.17",
"@types/node": "^10.12.18",
"@types/serverless": "^1.72.5",
"fork-ts-checker-webpack-plugin": "^3.0.1",
"serverless-dotenv-plugin": "^3.0.0",
"serverless-offline": "^6.7.0",
"serverless-webpack": "^5.2.0",
"ts-loader": "^5.3.3",
"ts-node": "^8.10.2",
"typescript": "^3.2.4",
"webpack": "^4.29.0",
"webpack-node-externals": "^1.7.2"
}
My function: import { APIGatewayProxyHandler } from 'aws-lambda';
import { S3Client } from '../lib/s3Client';
import 'source-map-support/register';
export const getSurveys: APIGatewayProxyHandler = async (_event, _context) => {
const s3Client = new S3Client();
const s3Response = await s3Client.get(
'databucket',
'surveys.json'
)
return {
statusCode: 200,
body: JSON.stringify(s3Response, null, 2),
};
} The first request works fine, I get back the correct response. The second request fails with;
//s3Client.ts
import { S3 } from 'aws-sdk';
type PutObjectRequest = S3.Types.PutObjectRequest;
type PutObjectOutput = S3.Types.PutObjectOutput;
export class S3Client {
protected client: S3;
public constructor() {
this.client = new S3();
}
public async put(bucket: string, fileName: string, contents: string): Promise<PutObjectOutput | null> {
const request: PutObjectRequest = {
Bucket: bucket,
Key: fileName,
Body: contents,
ContentType: 'application/json; charset=utf-8',
ACL: 'private',
CacheControl: 'max-age=60'
};
try {
const data = await this.client.putObject(request).promise();
if (!data) {
throw Error(`Writing file ${fileName} to bucket ${bucket} failed.`);
}
return data;
} catch (error) {
console.error(`Error when writing ${fileName} to bucket ${bucket}`, error);
return null;
}
}
public async get(bucket: string, fileName: string): Promise<object | null> {
const params = {
Bucket: bucket,
Key: fileName,
};
try {
const data = await this.client.getObject(params).promise();
if (!data || !data.Body) {
throw Error(`Reading file ${fileName} from bucket ${bucket} failed.`);
}
const body = data.Body?.toString('utf-8')
return JSON.parse(body);
} catch (error) {
console.error(`Error when reading ${fileName} from bucket ${bucket}`, error);
return null;
}
}
} If anyone has any ideas, let me know. Will keep working on it and post my solution. |
Bug Report
Current Behavior
Until 6.5.0, It worked with no issues. Then I upgraded to 6.7.0 then downgraded to 6.6.0 because of the issue below. I had to roll back to 6.5.0 again.
It doesn't crash at the beginning. After a request comes, then it crashes.
Sample Code
Environment
The text was updated successfully, but these errors were encountered: