(aws-tools): CLI `--hotswap` -> ` We don't support attributes of the 'AWS::DynamoDB::Table' resource`
See original GitHub issueWhat 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
AWS::DynamoDB::Table - AWS CloudFormation
This schema supports the provisioning of all table settings below. When using this schema in your AWS CloudFormation templates, please ensure that your...
Read more >Using Amazon DynamoDB with the AWS CLI
The AWS Command Line Interface (AWS CLI) provides support for all of the AWS database services, including Amazon DynamoDB. You can use the...
Read more >dynamodb — AWS CLI 1.27.37 Command Reference
With DynamoDB, you can create database tables that can store and retrieve any amount of data, and serve any level of request traffic....
Read more >Working with items and attributes - Amazon DynamoDB
You must provide the name of the table, along with the primary key of the item you want. Example. The following AWS CLI...
Read more >put-item — AWS CLI 1.27.35 Command Reference
If you supply a Value all by itself, DynamoDB assumes the attribute exists: You don't have to set Exists to true , because...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
⚠️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.