Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sam: cdk diff returns nothing when codeUri or events are changed #29185

Closed
pahud opened this issue Feb 20, 2024 · 4 comments · Fixed by #29223
Closed

sam: cdk diff returns nothing when codeUri or events are changed #29185

pahud opened this issue Feb 20, 2024 · 4 comments · Fixed by #29223
Labels
@aws-cdk/aws-sam Related to AWS Serverless Application Model bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@pahud
Copy link
Contributor

pahud commented Feb 20, 2024

Describe the bug

cdk diff returns nothing when I change the codeUri or events prop of sam.CfnFunction

 new sam.CfnFunction(this,`MarkLogicErrAlertFunction`,{
      codeUri: 's3://my-bucket/HelloWorldLambda12345.zip',
      handler: 'index.handler',
      runtime: 'nodejs16.x',
      // timeout: 300,
      // functionName: mailerfunctionName,
      // events: {
      //   TaskServerError: {
      //     properties: TaskServerErrorProperties,
      //     type: 'CloudWatchLogs',
      //   },

Expected Behavior

cdk diff should return the change

Current Behavior

it returns nothing

Reproduction Steps

Just deploy this for the first time

 new sam.CfnFunction(this,`MarkLogicErrAlertFunction`,{
      codeUri: 's3://my-bucket/HelloWorldLambda12345.zip',
      handler: 'index.handler',
      runtime: 'nodejs16.x',
      // timeout: 300,
      // functionName: mailerfunctionName,
      // events: {
      //   TaskServerError: {
      //     properties: TaskServerErrorProperties,
      //     type: 'CloudWatchLogs',
      //   },

and then modify codeUri or events, run cdk diff again.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

v2.126.0

Framework Version

No response

Node.js Version

v18.16.0

OS

mac

Language

TypeScript

Language Version

No response

Other information

No response

@pahud pahud added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 20, 2024
@github-actions github-actions bot added the @aws-cdk/aws-sam Related to AWS Serverless Application Model label Feb 20, 2024
@pahud
Copy link
Contributor Author

pahud commented Feb 20, 2024

internal tracking: V1258335352

@pahud pahud added p1 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 21, 2024
@mrgrain
Copy link
Contributor

mrgrain commented Feb 21, 2024

With the new change set based diff implemented in #28336 we are asking the CFN service for a list of changes. However the changes reported by CFN look like this:

[
  {
    "type": "Resource",
    "resourceChange": {
      "action": "Modify",
      "logicalResourceId": "MyFunction",
      "physicalResourceId": "SamStack-MyFunction-1234",
      "resourceType": "AWS::Lambda::Function",
      "replacement": "False",
      "scope": [
        "Properties"
      ],
      "details": [
        {
          "target": {
            "attribute": "Properties",
            "name": "Code",
            "requiresRecreation": "Never"
          },
          "evaluation": "Static",
          "changeSource": "DirectModification"
        }
      ]
    }
  }
]

Most notably, they are pointing to changes in a lambda function. This lambda function does not exists in the local template, since locally we have a SAM Function. Thus the diff tool fails to connect the reported diff the local template and silently drops the change.

@mrgrain
Copy link
Contributor

mrgrain commented Feb 21, 2024

Arguably the --no-change-set diff is better in this case:

➜  sam git:(main) ✗ cdk diff --no-change-set
Stack SamStack
Resources
[~] AWS::Serverless::Function MyFunction MyFunction replace
 └─ [~] CodeUri (requires replacement)
     ├─ [-] s3://my-bucket/HelloWorldLambda12345.zip
     └─ [+] s3://my-bucket/HelloWorldLambda.zip


✨  Number of stacks with differences: 1

@mergify mergify bot closed this as completed in #29223 Feb 23, 2024
mergify bot pushed a commit that referenced this issue Feb 23, 2024
### Issue # (if applicable)

Closes #29185

### Reason for this change

CFN applies the SAM transform before the changeset is created. This means that SAM resources become their underlying CFN types in the template that the changeset operates on. This means that the changeset is operating on resources that we don't see in our template. 

### Description of changes

Before, if we saw properties in our diff that were not in the changeset (like `codeUri` for `Serverless::Function`, which doesn't appear in the changeset, because it becomes `Code` for `Lambda::Function`), we'd filter them out of the diff. We now skip this process for SAM resources.

### Description of how you validated changes

unit test

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-sam Related to AWS Serverless Application Model bug This issue is a bug. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants