
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@aws/lambda-invoke-store
Advanced tools
Invoke scoped data storage for AWS Lambda Node.js Runtime Environment
@aws/lambda-invoke-store provides a generic, per-invocation context store for
AWS Lambda Node.js Runtime Environment. It enables storing and retrieving data
within the scope of a single Lambda invocation, with proper isolation between
concurrent executions.
npm install @aws/lambda-invoke-store
Note: In the AWS Lambda environment, the Runtime Interface Client (RIC) automatically initializes the InvokeStore context at the beginning of each invocation. Lambda function developers typically don't need to call
InvokeStore.run()directly.
import { InvokeStore } from "@aws/lambda-invoke-store";
// Lambda handler with invoke store
export const handler = async (event, context) => {
// The RIC has already initialized the InvokeStore with requestId and X-Ray traceId
// Access Lambda context data
console.log(`Processing request: ${InvokeStore.getRequestId()}`);
// Store custom data
InvokeStore.set("userId", event.userId);
// Data persists across async operations
await processData(event);
// Retrieve custom data
const userId = InvokeStore.get("userId");
return {
requestId: InvokeStore.getRequestId(),
userId,
};
};
// Context is preserved in async operations
async function processData(event) {
// Still has access to the same invoke context
console.log(`Processing in same context: ${InvokeStore.getRequestId()}`);
// Can set additional data
InvokeStore.set("processedData", { result: "success" });
}
Returns the complete current context or undefined if outside a context.
const context = InvokeStore.getContext();
Gets a value from the current context.
const requestId = InvokeStore.get(InvokeStore.PROTECTED_KEYS.REQUEST_ID);
const customValue = InvokeStore.get("customKey");
Sets a custom value in the current context. Protected Lambda fields cannot be modified.
InvokeStore.set("userId", "user-123");
InvokeStore.set("timestamp", Date.now());
// This will throw an error:
// InvokeStore.set(InvokeStore.PROTECTED_KEYS.REQUEST_ID, 'new-id');
Convenience method to get the current request ID.
const requestId = InvokeStore.getRequestId(); // Returns '-' if outside context
Convenience method to get the tenant ID.
const requestId = InvokeStore.getTenantId();
Convenience method to get the current X-Ray trace ID. This ID is used for distributed tracing across AWS services.
const traceId = InvokeStore.getXRayTraceId(); // Returns undefined if not set or outside context
Checks if code is currently running within an invoke context.
if (InvokeStore.hasContext()) {
// We're inside an invoke context
}
Note: This method is primarily used by the Lambda Runtime Interface Client (RIC) to initialize the context for each invocation. Lambda function developers typically don't need to call this method directly.
Runs a function within an invoke context.
InvokeStore.run(
{
[InvokeStore.PROTECTED_KEYS.REQUEST_ID]: "request-123",
[InvokeStore.PROTECTED_KEYS.X_RAY_TRACE_ID]: "trace-456", // Optional X-Ray trace ID
customField: "value", // Optional custom fields
},
() => {
// Function to execute within context
}
);
The @aws/lambda-invoke-store package is designed to be integrated with the AWS Lambda Node.js Runtime Interface Client (RIC). The RIC automatically:
requestId and X-Ray traceId in the contextLambda function developers can focus on using the context without worrying about initialization or cleanup.
The InvokeStore uses a singleton pattern to ensure that all imports of the module use the same instance, which is critical for maintaining proper context isolation across different parts of your application.
The InvokeStore integrates with the Lambda runtime's global namespace:
// The InvokeStore is available globally
const globalInstance = globalThis.awslambda.InvokeStore;
This enables seamless integration between the Lambda Runtime Interface Client (RIC), AWS SDK, and your function code, ensuring they all share the same context.
If you prefer not to modify the global namespace, you can opt out by setting the environment variable:
# Disable global namespace modification
AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA=1
When this environment variable is set, the InvokeStore will still function correctly, but it won't be stored in the global namespace.
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.
FAQs
Invoke scoped data storage for AWS Lambda Node.js Runtime Environment
The npm package @aws/lambda-invoke-store receives a total of 7,970,158 weekly downloads. As such, @aws/lambda-invoke-store popularity was classified as popular.
We found that @aws/lambda-invoke-store demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 18 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.