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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Validate parameters and permissions without any function code or configuration m
code-artifacts-dir: my-code-artifacts-dir
dry-run: true
```
**Note**: Dry run will still call `GetFunctionConfiguration` to check if the function exists and perform configuration diffs against what's currently deployed.
## Build from Source

To automate building your source code, add a build step based on your runtime and build process. This build step should be performed before the AWS Lambda Deploy step, and AWS Lambda Deploy's `code-artifacts-dir` parameter will typically be set to the build step's code artifact output directory.
Expand Down
71 changes: 70 additions & 1 deletion __tests__/dry_run_mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,73 @@ describe('Dry Run Mode Tests', () => {

await mainModule.run();
});
});

test('should check if function exists even in dry run mode', async () => {
const mockSend = jest.fn()
// First call: checkFunctionExists - function exists
.mockResolvedValueOnce({ Runtime: 'nodejs18.x' })
// Second call: GetFunctionConfigurationCommand for config check
.mockResolvedValueOnce({ Runtime: 'nodejs18.x', MemorySize: 256 })
// Third call: UpdateFunctionCodeCommand dry run
.mockResolvedValueOnce({
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:test-function',
Version: '$LATEST'
});

const mockClient = { send: mockSend };
LambdaClient.mockImplementation(() => mockClient);

validations.validateAllInputs = jest.fn().mockReturnValue({
valid: true,
functionName: 'test-function',
parsedEnvironment: {},
dryRun: true,
codeArtifactsDir: './code'
});

jest.spyOn(mainModule, 'packageCodeArtifacts').mockResolvedValue('/tmp/test.zip');
const fs = require('fs/promises');
fs.readFile = jest.fn().mockResolvedValue(Buffer.from('test'));

await mainModule.run();

// Verify that checkFunctionExists was called (first send call should be GetFunctionConfigurationCommand)
expect(mockSend).toHaveBeenCalled();
expect(mockSend.mock.calls[0][0].constructor.name).toEqual('GetFunctionConfigurationCommand');

// Verify dry run proceeded successfully
expect(core.info).toHaveBeenCalledWith('Checking if test-function exists');
expect(core.info).toHaveBeenCalledWith('DRY RUN MODE: No AWS resources will be created or modified');
expect(core.setFailed).not.toHaveBeenCalledWith('DRY RUN MODE can only be used for updating function code of existing functions');
});

test('should fail dry run mode when function does not exist', async () => {
const mockSend = jest.fn()
// checkFunctionExists - function does not exist (ResourceNotFoundException)
.mockRejectedValueOnce({ name: 'ResourceNotFoundException' });

const mockClient = { send: mockSend };
LambdaClient.mockImplementation(() => mockClient);

validations.validateAllInputs = jest.fn().mockReturnValue({
valid: true,
functionName: 'non-existent-function',
parsedEnvironment: {},
dryRun: true,
codeArtifactsDir: './code'
});

jest.spyOn(mainModule, 'packageCodeArtifacts').mockResolvedValue('/tmp/test.zip');

await mainModule.run();

// Verify that checkFunctionExists was called (first send call should be GetFunctionConfigurationCommand)
expect(mockSend).toHaveBeenCalled();
expect(mockSend.mock.calls[0][0].constructor.name).toEqual('GetFunctionConfigurationCommand');

// Verify dry run failed with correct error message
expect(core.info).toHaveBeenCalledWith('Checking if non-existent-function exists');
expect(core.info).toHaveBeenCalledWith('DRY RUN MODE: No AWS resources will be created or modified');
expect(core.setFailed).toHaveBeenCalledWith('DRY RUN MODE can only be used for updating function code of existing functions');
});
});
15 changes: 12 additions & 3 deletions __tests__/s3_key_generation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,26 @@ describe('S3 Key Generation and Dry Run Tests', () => {
});

test('should log dry run message and fail when function does not exist', async () => {
const mockSend = jest.fn()
// checkFunctionExists - function does not exist (ResourceNotFoundException)
.mockRejectedValueOnce({ name: 'ResourceNotFoundException' });

const mockClient = { send: mockSend };
LambdaClient.mockImplementation(() => mockClient);

validations.validateAllInputs = jest.fn().mockReturnValue({
valid: true,
functionName: 'test-function',
dryRun: true
parsedEnvironment: {},
dryRun: true,
codeArtifactsDir: './code'
});

jest.spyOn(mainModule, 'checkFunctionExists').mockResolvedValue(false);
jest.spyOn(mainModule, 'packageCodeArtifacts').mockResolvedValue('/tmp/test.zip');

await mainModule.run();

expect(core.info).toHaveBeenCalledWith('DRY RUN MODE: No AWS resources will be created or modified');
expect(core.setFailed).toHaveBeenCalledWith('DRY RUN MODE can only be used for updating function code of existing functions');
});
});
});
Loading
Loading