Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/idempotency/src/persistence/BasePersistenceLayer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHash, type Hash } from 'node:crypto';
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
import { LRUCache } from '@aws-lambda-powertools/commons/utils/lru-cache';
import { getStringFromEnv } from '@aws-lambda-powertools/commons/utils/env';
import { LRUCache } from '@aws-lambda-powertools/commons/utils/lru-cache';
import { search } from '@aws-lambda-powertools/jmespath';
import type { JMESPathParsingOptions } from '@aws-lambda-powertools/jmespath/types';
import { IdempotencyRecordStatus } from '../constants.js';
Expand Down Expand Up @@ -39,7 +39,7 @@ abstract class BasePersistenceLayer implements BasePersistenceLayerInterface {
public constructor() {
this.idempotencyKeyPrefix = getStringFromEnv({
key: 'AWS_LAMBDA_FUNCTION_NAME',
errorMessage: 'AWS_LAMBDA_FUNCTION_NAME environment variable is required',
defaultValue: '',
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ describe('Class: BasePersistenceLayer', () => {
})
);
});

it('initializes with empty key prefix if AWS_LAMBDA_FUNCTION_NAME is not in the environment variable', () => {
// Prepare
vi.stubEnv('AWS_LAMBDA_FUNCTION_NAME', undefined);

// Act
const persistenceLayer = new PersistenceLayerTestClass();

// Assess
expect(persistenceLayer.idempotencyKeyPrefix).toBe('');
expect(persistenceLayer).toEqual(
expect.objectContaining({
configured: false,
expiresAfterSeconds: 3600,
hashFunction: 'md5',
payloadValidationEnabled: false,
throwOnNoIdempotencyKey: false,
useLocalCache: false,
})
);
});
});

describe('Method: configure', () => {
Expand Down