diff --git a/packages/aws-cdk/lib/api/hotswap-deployments.ts b/packages/aws-cdk/lib/api/hotswap-deployments.ts index f64e5c16eddfa..487d8a1dd2281 100644 --- a/packages/aws-cdk/lib/api/hotswap-deployments.ts +++ b/packages/aws-cdk/lib/api/hotswap-deployments.ts @@ -68,6 +68,11 @@ async function findAllHotswappableChanges( sdk: ISDK, nestedStackNames: { [nestedStackName: string]: NestedStackNames }, ): Promise { + // Skip hotswap if there is any change on stack outputs + if (stackChanges.outputs.differenceCount > 0) { + return undefined; + } + const resourceDifferences = getStackResourceDifferences(stackChanges); let foundNonHotswappableChange = false; diff --git a/packages/aws-cdk/test/api/hotswap/hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/hotswap-deployments.test.ts index e7436e8d127ec..4c3bd67ee764c 100644 --- a/packages/aws-cdk/test/api/hotswap/hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/hotswap-deployments.test.ts @@ -356,3 +356,61 @@ test('changing the type of a deployed resource always results in a full deployme expect(mockUpdateMachineDefinition).not.toHaveBeenCalled(); expect(mockUpdateLambdaCode).not.toHaveBeenCalled(); }); + +test('A change to both a hotswappable resource and a stack output results in a full deployment', async () => { + // GIVEN + setup.setCurrentCfnStackTemplate({ + Resources: { + Func: { + Type: 'AWS::Lambda::Function', + Properties: { + Code: { + S3Bucket: 'current-bucket', + S3Key: 'current-key', + }, + FunctionName: 'my-function', + }, + Metadata: { + 'aws:asset:path': 'old-path', + }, + }, + }, + Outputs: { + SomeOutput: { + Value: 'old-value', + }, + }, + }); + const cdkStackArtifact = setup.cdkStackArtifactOf({ + template: { + Resources: { + Func: { + Type: 'AWS::Lambda::Function', + Properties: { + Code: { + S3Bucket: 'current-bucket', + S3Key: 'new-key', + }, + FunctionName: 'my-function', + }, + Metadata: { + 'aws:asset:path': 'new-path', + }, + }, + }, + Outputs: { + SomeOutput: { + Value: 'new-value', + }, + }, + }, + }); + + // WHEN + const deployStackResult = await hotswapMockSdkProvider.tryHotswapDeployment(cdkStackArtifact); + + // THEN + expect(deployStackResult).toBeUndefined(); + expect(mockUpdateMachineDefinition).not.toHaveBeenCalled(); + expect(mockUpdateLambdaCode).not.toHaveBeenCalled(); +});