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

(aws-tools): CLI --hotswap -> We don't support attributes of the 'AWS::DynamoDB::Table' resource #19421

Closed
kbakk opened this issue Mar 16, 2022 · 8 comments · Fixed by #19620
Closed
Assignees
Labels
feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. p2 package/tools Related to AWS CDK Tools or CLI

Comments

@kbakk
Copy link

kbakk commented Mar 16, 2022

What is the problem?

When using nested stacks, and a DynamoDB table is created in the parent stack, --hotswap will not work.

Reproduction Steps

Python reproducer

Initialize project with cdk init sample-app --language python and create/change:

app.py

import aws_cdk as cdk

from cdk_py_workshop.cdk_py_workshop_stack import ApiStack, DatabaseStack


app = cdk.App()
parent = DatabaseStack(app, "cdk-py-workshop-database")
ApiStack(parent, "cdk-py-workshop-api", table=parent.table)

app.synth()

cdk_py_workshop/cdk_py_workshop_stack.py

from constructs import Construct
from aws_cdk import (
    Stack,
    NestedStack,
    aws_lambda as _lambda,
    aws_apigateway as apigw,
    aws_dynamodb as ddb
)

class DatabaseStack(Stack):
    def __init__(self, scope: Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)
        self.table = ddb.Table(
            self, 'Hits',
            partition_key={'name': 'path', 'type': ddb.AttributeType.STRING}
        )

class ApiStack(NestedStack):

    def __init__(self, scope: Construct, id: str, table, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)
        my_lambda = _lambda.Function(
            self, 'HelloHandler',
            runtime=_lambda.Runtime.PYTHON_3_7,
            code=_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
            environment={"TABLE": table.table_name}
        )
        table.grant_read_write_data(my_lambda)
        apigw.LambdaRestApi(
            self, 'Endpoint',
            handler=my_lambda,
        )

lambda/hello.py

def handler(event, context):
    print(f'request: {event}')

Run cdk deploy once, then modify lambda/hello.py (e.g. add another print). Try to run cdk deploy --hotswap.

What did you expect to happen?

Super fast hotswap of my lambda function and an output like ✨ Total time: 10.97s (or less 🤩 )

What actually happened?

I'm getting this message:

✨  Synthesis time: 7.16s

⚠️ The --hotswap flag deliberately introduces CloudFormation drift to speed up deployments
⚠️ It should only be used for development - never use it for your production Stacks!
cdk-py-workshop-database: deploying...
[ ... removed ... ]
Could not perform a hotswap deployment, because the CloudFormation template could not be resolved: We don't support attributes of the 'AWS::DynamoDB::Table' resource. This is a CDK limitation. Please report it at https://github.com/aws/aws-cdk/issues/new/choose
Falling back to doing a full deployment
cdk-py-workshop-database: creating CloudFormation changeset...

 ✅  cdk-py-workshop-database

✨  Deployment time: 70.7s

Stack ARN:
arn:aws:cloudformation:eu-west-1:012345678900:stack/cdk-py-workshop-database/fc7aeb10-a530-11ec-81af-0a3d49828e3b

✨  Total time: 77.86s

And CDK runs a full deployment.

CDK CLI Version

2.16.0 (build 4c77925)

Framework Version

No response

Node.js Version

v16.14.0

OS

Debian GNU/Linux 11

Language

Python

Language Version

Python 3.9.10

Other information

No response

@kbakk kbakk added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 16, 2022
@github-actions github-actions bot added the @aws-cdk/aws-dynamodb Related to Amazon DynamoDB label Mar 16, 2022
@ryparker
Copy link
Contributor

ryparker commented Mar 16, 2022

Hey @kbakk 👋🏻

Thanks for opening this issue. I'm going to convert this into a feature-request seeing as we currently don't support Hot swapping with Dynamo DB.

Currently hot swapping supports Lambda functions, Step Functions state machines, and Amazon ECS container images.

CDK CLI docs

However this issue will be used to track this request and collect community interest. We use +1s to help us prioritize our work, and as always we are happy to take contributions if anyone is interested to pick this up and submit a PR (please make sure to follow our contribution guidelines.) 🙏

@ryparker ryparker added p2 feature-request A feature should be added or improved. and removed bug This issue is a bug. labels Mar 16, 2022
@ryparker ryparker changed the title (aws_dynamodb): CLI --hotswap -> We don't support attributes of the 'AWS::DynamoDB::Table' resource (aws-tools): CLI --hotswap -> We don't support attributes of the 'AWS::DynamoDB::Table' resource Mar 16, 2022
@ryparker ryparker added package/tools Related to AWS CDK Tools or CLI and removed @aws-cdk/aws-dynamodb Related to Amazon DynamoDB labels Mar 16, 2022
@hoegertn
Copy link
Contributor

What attributes of a table should be hotswappable? I am afraid we might open Pandora's box if we allow hotswapping for too many resources.

@matmeylan
Copy link

What do you think of allowing developers to still use hotswapp for resources that are hot swappable (lambda, ecs, etc), even if there is not supported resources in the stack ?

Hear me out:

In our case for instance, the need for hotswap is quite high. Full deployments take ~10 minutes. Hotswapping would reduce dev deployments dramatically, hence increase our DX tremendously. But, because we're using RDS (same problem as for Dynamo users), we can't use hotswapp. But, I'd be more than happy to use hotswapp without RDS support. I could always use a full deployment when I need to update the DB.

@skinny85
Copy link
Contributor

@kbakk thanks for opening the issue. Can you actually show your CDK code, and the exact command you are executing to trigger the hotswap deployment?

Thanks,
Adam

@skinny85 skinny85 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 28, 2022
@kbakk
Copy link
Author

kbakk commented Mar 28, 2022

@skinny85 Hi, did you see the expandable section "Python reproduce" in the description? Is there anything in addition that's wanted here?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 28, 2022
@skinny85
Copy link
Contributor

skinny85 commented Mar 28, 2022

@skinny85 Hi, did you see the expandable section "Python reproduce" in the description?

I in fact did not see it 😃. Thanks, I think that's all I need!

@skinny85
Copy link
Contributor

I was able to reproduce this - working on a fix!

skinny85 added a commit to skinny85/aws-cdk that referenced this issue Mar 29, 2022
@mergify mergify bot closed this as completed in #19620 Apr 1, 2022
mergify bot pushed a commit that referenced this issue Apr 1, 2022
When using Nested Stacks, Parameters are used to pass values between the parent and child Stacks.
A customer had a setup where a DynamoDB Table was in the parent Stack,
and a Lambda using that Table (through environment variables) was in the child Stack.
In order to be able to hotswap the Lambda in the child Stack,
we have to correctly resolve attributes of the `AWS::DynamoDB::Table` resource,
like `Ref` and `Arn`, to resolve the values of the Parameters passed to the child Stack.

Fixes #19421

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

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

github-actions bot commented Apr 1, 2022

⚠️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.

This was referenced Apr 7, 2022
mergify bot added a commit that referenced this issue Apr 7, 2022
See [CHANGELOG](https://github.com/aws/aws-cdk/blob/bump/1.152.0/CHANGELOG.md)

For convenience, extracted the relevant CHANGELOG entry:

## [1.152.0](v1.151.0...v1.152.0) (2022-04-06)


### Features

* **cfnspec:** cloudformation spec v63.0.0 ([#19679](#19679)) ([dba96a9](dba96a9))
* **cfnspec:** cloudformation spec v65.0.0 ([#19745](#19745)) ([796fc64](796fc64))
* **cli:** add --build option ([#19663](#19663)) ([eb9b8e2](eb9b8e2)), closes [#19667](#19667)
* **cli:** preview of `cdk import` ([#17666](#17666)) ([4f12209](4f12209))
* **core:** throw error when stack name exceeds max length ([#19725](#19725)) ([1ffd45e](1ffd45e))
* **eks:** add k8s v1.22 ([#19756](#19756)) ([9a518c5](9a518c5))
* **opensearch:** Add latest Opensearch Version 1.2 ([#19749](#19749)) ([a2ac36e](a2ac36e))
* add new integration test runner ([#19754](#19754)) ([1b4d010](1b4d010))
* **eks:** alb-controller v2.4.1 ([#19653](#19653)) ([1ec08df](1ec08df))
* **lambda:** add support for ephemeral storage ([#19552](#19552)) ([f1d9b6a](f1d9b6a)), closes [#19605](#19605)
* **s3:** EventBridge bucket notifications ([#18614](#18614)) ([d8e602b](d8e602b)), closes [#18076](#18076)
* **synthetics:** new puppeteer 3.5 runtime ([#19673](#19673)) ([ce2b91b](ce2b91b)), closes [#19634](#19634)


### Bug Fixes

* **aws_applicationautoscaling:** Add missing members to PredefinedMetric enum ([#18978](#18978)) ([75a6fa7](75a6fa7)), closes [#18969](#18969)
* **cli:** apps with many resources scroll resource output offscreen ([#19742](#19742)) ([053d22c](053d22c)), closes [#19160](#19160)
* **cli:** support attributes of DynamoDB Tables for hotswapping ([#19620](#19620)) ([2321ece](2321ece)), closes [#19421](#19421)
* **cloudwatch:** automatic metric math label cannot be suppressed ([#17639](#17639)) ([7fa3bf2](7fa3bf2))
* **codedeploy:** add name validation for Application, Deployment Group and Deployment Configuration ([#19473](#19473)) ([9185042](9185042))
* **codedeploy:** the Service Principal is wrong in isolated regions ([#19729](#19729)) ([7e9a43d](7e9a43d)), closes [#19399](#19399)
* **core:** `Fn.select` incorrectly short-circuits complex expressions ([#19680](#19680)) ([7f26fad](7f26fad))
* **core:** detect and resolve stringified number tokens ([#19578](#19578)) ([7d9ab2a](7d9ab2a)), closes [#19546](#19546) [#19550](#19550)
* **core:** reduce CFN template indent size to save bytes ([#19656](#19656)) ([fd63ca3](fd63ca3))
* **ecs:** 'desiredCount' and 'ephemeralStorageGiB' cannot be tokens ([#19453](#19453)) ([c852239](c852239)), closes [#16648](#16648)
* **ecs:** remove unnecessary error when adding volume to external task definition ([#19774](#19774)) ([5446ded](5446ded)), closes [#19259](#19259)
* **iam:** policies aren't minimized as far as possible ([#19764](#19764)) ([876ed8a](876ed8a)), closes [#19751](#19751)
* **logs:** Faulty Resource Policy Generated ([#19640](#19640)) ([1fdf122](1fdf122)), closes [#17544](#17544)
mergify bot added a commit that referenced this issue Apr 7, 2022
See [CHANGELOG](https://github.com/aws/aws-cdk/blob/bump/2.20.0/CHANGELOG.md)

For convenience, extracted the relevant CHANGELOG entry:

## [2.20.0](v2.19.0...v2.20.0) (2022-04-07)


### Features

* **cfnspec:** cloudformation spec v63.0.0 ([#19679](#19679)) ([dba96a9](dba96a9))
* **cfnspec:** cloudformation spec v65.0.0 ([#19745](#19745)) ([796fc64](796fc64))
* **cli:** add --build option ([#19663](#19663)) ([eb9b8e2](eb9b8e2)), closes [#19667](#19667)
* **cli:** preview of `cdk import` ([#17666](#17666)) ([4f12209](4f12209))
* **core:** throw error when stack name exceeds max length ([#19725](#19725)) ([1ffd45e](1ffd45e))
* **eks:** add k8s v1.22 ([#19756](#19756)) ([9a518c5](9a518c5))
* **opensearch:** Add latest Opensearch Version 1.2 ([#19749](#19749)) ([a2ac36e](a2ac36e))
* add new integration test runner ([#19754](#19754)) ([1b4d010](1b4d010))
* **eks:** alb-controller v2.4.1 ([#19653](#19653)) ([1ec08df](1ec08df))
* **lambda:** add support for ephemeral storage ([#19552](#19552)) ([f1d9b6a](f1d9b6a)), closes [#19605](#19605)
* **s3:** EventBridge bucket notifications ([#18614](#18614)) ([d8e602b](d8e602b)), closes [#18076](#18076)


### Bug Fixes

* **aws_applicationautoscaling:** Add missing members to PredefinedMetric enum ([#18978](#18978)) ([75a6fa7](75a6fa7)), closes [#18969](#18969)
* **cli:** apps with many resources scroll resource output offscreen ([#19742](#19742)) ([053d22c](053d22c)), closes [#19160](#19160)
* **cli:** support attributes of DynamoDB Tables for hotswapping ([#19620](#19620)) ([2321ece](2321ece)), closes [#19421](#19421)
* **cloudwatch:** automatic metric math label cannot be suppressed ([#17639](#17639)) ([7fa3bf2](7fa3bf2))
* **codedeploy:** add name validation for Application, Deployment Group and Deployment Configuration ([#19473](#19473)) ([9185042](9185042))
* **codedeploy:** the Service Principal is wrong in isolated regions ([#19729](#19729)) ([7e9a43d](7e9a43d)), closes [#19399](#19399)
* **core:** `Fn.select` incorrectly short-circuits complex expressions ([#19680](#19680)) ([7f26fad](7f26fad))
* **core:** detect and resolve stringified number tokens ([#19578](#19578)) ([7d9ab2a](7d9ab2a)), closes [#19546](#19546) [#19550](#19550)
* **core:** reduce CFN template indent size to save bytes ([#19656](#19656)) ([fd63ca3](fd63ca3))
* **ecs:** 'desiredCount' and 'ephemeralStorageGiB' cannot be tokens ([#19453](#19453)) ([c852239](c852239)), closes [#16648](#16648)
* **ecs:** remove unnecessary error when adding volume to external task definition ([#19774](#19774)) ([5446ded](5446ded)), closes [#19259](#19259)
* **iam:** policies aren't minimized as far as possible ([#19764](#19764)) ([876ed8a](876ed8a)), closes [#19751](#19751)
* **logs:** Faulty Resource Policy Generated ([#19640](#19640)) ([1fdf122](1fdf122)), closes [#17544](#17544)
StevePotter pushed a commit to StevePotter/aws-cdk that referenced this issue Apr 27, 2022
…19620)

When using Nested Stacks, Parameters are used to pass values between the parent and child Stacks.
A customer had a setup where a DynamoDB Table was in the parent Stack,
and a Lambda using that Table (through environment variables) was in the child Stack.
In order to be able to hotswap the Lambda in the child Stack,
we have to correctly resolve attributes of the `AWS::DynamoDB::Table` resource,
like `Ref` and `Arn`, to resolve the values of the Parameters passed to the child Stack.

Fixes aws#19421

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants