Skip to content

Instantly share code, notes, and snippets.

@perpil
Last active November 12, 2024 16:54
Show Gist options
  • Select an option

  • Save perpil/e9b1bb63f7d5534e41f10d9f886a7cb1 to your computer and use it in GitHub Desktop.

Select an option

Save perpil/e9b1bb63f7d5534e41f10d9f886a7cb1 to your computer and use it in GitHub Desktop.
Get node lambda runtime build date at run time
import { statSync } from "fs";
let runtimeBuildDate;
try {
runtimeBuildDate = statSync("/var/runtime").mtime;
} catch (e) {
console.error("Unable to determine runtime build date", e);
}
export const handler = async (event) => {
const response = {
statusCode: 200,
body: JSON.stringify({runtimeBuildDate, nodeVersion:process.version}),
};
return response;
};
@perpil
Copy link
Author

perpil commented Nov 12, 2024

Snippet from my CDK NodeJsFunction to replace the environment variable process.env.sdkVersion with current AWS SDK version at build time using esbuild define:

define: {
          "process.env.sdkVersion": JSON.stringify(
            JSON.parse(
              readFileSync(
                "node_modules/@aws-sdk/client-sts/package.json"
              ).toString()
            ).version
          )
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment