You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, this is very old syntax. It was deprecated with the 0.11.x runtime and backfilled (poorly) into the new runtimes.
Since the docs now recommend running Node 8.10, this function should be rewritten using the more understandable async/await syntax. Here are the docs stating that it's available in the 8.10 runtime.
Rewriting the function to use async await will transition the runtime to use the explicit callback parameter, marked by when the function resolves the promise returned by the exports.handler method.
How I Discovered This
Because we're defining this lambda in our Infrastructure-as-Code repository (using Terraform), we encrypt the SUMO_ENDPOINT URL since we don't want anyone other than the lambda to be able to see it (a malicious actor could POST logs to the endpoint and run up our bill).
To do this, I made the exports.handler asynchronous and decrypt the KMS key before parsing the message and sending it to sumo.
constAWS=require('aws-sdk');asyncfunctiongetSumoUrl(){varkms=newAWS.KMS();varkmsDecryptParams={CiphertextBlob: Buffer.from(process.env.ENCRYPTED_SUMO_ENDPOINT,'base64')};vardata=awaitkms.decrypt(kmsDecryptParams).promise();vardecryptedSumoEndpoint=data.Plaintext.toString('utf-8');returndecryptedSumoEndpoint;}// existing code unchanged// NOTE that this is async nowexports.handler=asyncfunction(event,context){SumoURL=awaitgetSumoUrl();// existing code unchanged}
However, this did not work because of the reliance on the old, unsupported context.succeed call. This would have been a whole lot easier if the rest of the function used the newer Node 8 async/await syntax to start with.
Conclusion / Suggestions
It seems like this lambda was written a long time ago, based on the APIs it's using. Node has come quite a long way and rewriting with Node 8 standards would make it more readable and extensible for users.
The text was updated successfully, but these errors were encountered:
Yes agree and we use callback() in our new version of cloudwatch lambda function (dlq_processor). @duchatran do we want to maintain backward compatibility with old nodejs versions? Otherwise I can migrate this one to async await which will save us from callback hell.
So I think it'd probably be fair to drop the backwards compatibility. Additionally, Node 4 has been deprecated on the lambda side so I'd assume folks will upgrade to the latest runtime when updating their lambdas.
The Problem
In the current cloudwatch_lambda.js (pinned version link), the lambda is being marked as complete by calling
context.succeed
:sumologic-aws-lambda/cloudwatchlogs/cloudwatchlogs_lambda.js
Line 96 in 22a1dcb
However, this is very old syntax. It was deprecated with the 0.11.x runtime and backfilled (poorly) into the new runtimes.
Since the docs now recommend running Node 8.10, this function should be rewritten using the more understandable async/await syntax. Here are the docs stating that it's available in the 8.10 runtime.
Rewriting the function to use async await will transition the runtime to use the explicit
callback
parameter, marked by when the function resolves the promise returned by theexports.handler
method.How I Discovered This
Because we're defining this lambda in our Infrastructure-as-Code repository (using Terraform), we encrypt the
SUMO_ENDPOINT
URL since we don't want anyone other than the lambda to be able to see it (a malicious actor could POST logs to the endpoint and run up our bill).To do this, I made the
exports.handler
asynchronous and decrypt the KMS key before parsing the message and sending it to sumo.However, this did not work because of the reliance on the old, unsupported
context.succeed
call. This would have been a whole lot easier if the rest of the function used the newer Node 8 async/await syntax to start with.Conclusion / Suggestions
It seems like this lambda was written a long time ago, based on the APIs it's using. Node has come quite a long way and rewriting with Node 8 standards would make it more readable and extensible for users.
The text was updated successfully, but these errors were encountered: