-
Notifications
You must be signed in to change notification settings - Fork 67
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
How do I use the OnResult function correctly? #613
Comments
The property is call |
Interesting @dontirun I actually had is as onResult in my original code. But it didn't send across the event to my Lambda functions so I presumed I did it wrong and it should be resultDest. I originally had this const BackEndBucket = S3.Bucket.fromBucketName(
this,
`mybucket`,
`mybucket`,
);
const clamScanDeleteLambda = new lambda.Function(this, 'clamscan-delete-file', {
runtime: lambda.Runtime.NODEJS_14_X,
code: lambda.Code.fromAsset('lambda'),
handler: 'index.handler',
});
const sc = new ServerlessClamscan(this, 'Clamscan', {
acceptResponsibilityForUsingImportedBucket: true,
onResult: new destinations.LambdaDestination(clamScanDeleteLambda)
});
sc.addSourceBucket(BackEndBucket);
sc.infectedRule?.addTarget(
new SnsTopic(infectedTopic, {
message: RuleTargetInput.fromEventPath(
'$.detail',
),
}),
); I can see the destination was added on the ClamScan Lambda Function, but when I uploaded an infected file into S3, it marked it as infected correctly, but no logs indicated that the Lambda function was actually called. My Lambda function is just this for testing reasons right now. Lambda Function exports.handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
event
};
return response;
}; Anything obvious I am missing? I can't see why this wouldn't work. What I'm trying to achieve here is a way to delete the files straight away once they have been marked as infected, so my idea was to take the event and just write some code to delete the infected file. |
That's strange. Does the |
Good point @dontirun is there a way I can even add that, because the scan lambda is inside your module? 🤔 So the ClamscanServerlessClamscan is being called, I can see the cloudwatch logs but its not calling the Lambda function at the same time, I'm thinking maybe I should put an SNS Queue before the Lambda function to see if that fixes this, its a bit strange though. 🤔 |
@dontirun Okay so, im wrong it is being invoked, for some reason if you don't log anything with console.log() it doesn't log any logs to say the Lambda function ran 🤔 I'm not sure if thats by design or not, but I am now receiving the payload so I can handle it. Example Payload:
|
@dontirun I have a quick question for you, sorry to be a pain! So for example, when someone is uploading a file in our code, our developer wants to invoke this lambda function with the file and see if its infected, I am not sure what inputs the lambda requires, and if this is at all possible? |
Not with how the solution is currently designed. Additionally lambda destinations (so the infected file delete you have set up) doesn't run if the scan lambda is invoked synchronously, lambda destinations only work on asynchronous invokes |
Hello!
Sorry I'm back with another question, so I want to use the onResult function to send the payload to a Lambda function so I have done this in CDK.
However it doesn't seem to like the destination defined in this way?
Object literal may only specify known properties, and 'resultDest' does not exist in type 'ServerlessClamscanProps'.ts(2345)
Am I doing this wrong?
The text was updated successfully, but these errors were encountered: