task_definition.add_volume: Error occuring during cdk synth with the module in cdk python
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
When trying to use [task_definition.add_volume](https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_ecs/Volume.html) method in cdk python, it fails with the error below.
```
.venv)@b0be836c5e1c pythoncdk % cdk synth
Traceback (most recent call last):
File "/Users//Desktop/pythoncdk/app.py", line 10, in
PythoncdkStack(app, "PythoncdkStack",
File "/Users//Desktop/pythoncdk/.venv/lib/python3.11/site-packages/jsii/_runtime.py", line 118, in __call__
inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users//Desktop/pythoncdk/pythoncdk/pythoncdk_stack.py", line 52, in __init__
task_definition.add_volume(volume)
TypeError: TaskDefinition.add_volume() takes 1 positional argument but 2 were given
Subprocess exited with error 1
```
Code used by me:
```
from aws_cdk import (
# Duration,
Stack,
Size,
aws_rds as rds,
# aws_sqs as sqs,
aws_ec2 as ec2,
aws_ecs as ecs,
aws_appconfig as aws_appconfig,
)
from constructs import Construct
class PythoncdkStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# The code that defines your stack goes here
cluster = ecs.Cluster(self, 'cluster')
task_definition = ecs.FargateTaskDefinition(self, "TaskDef")
container = task_definition.add_container("web",
image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
port_mappings=[ecs.PortMapping(
container_port=80,
protocol=ecs.Protocol.TCP
)]
)
volume = ecs.ServiceManagedVolume(self, "EBSVolume",
name="ebs1",
managed_ebs_volume=ecs.ServiceManagedEBSVolumeConfiguration(
size=Size.gibibytes(15),
volume_type=ec2.EbsDeviceVolumeType.GP3,
file_system_type=ecs.FileSystemType.XFS,
tag_specifications=[ecs.EBSTagSpecification(
tags={
"purpose": "production"
},
propagate_tags=ecs.EbsPropagatedTagSource.SERVICE
)]
)
)
volume.mount_in(container,
container_path="/var/lib",
read_only=False
)
task_definition.add_volume(volume)
```
### Expected Behavior
Expected behaviour of this method is to add the volume and synthesize template without any issue. This is possible using typescript, only errors out in python.
### Current Behavior
Error occurs during synth:
```
(.venv)@b0be836c5e1c pythoncdk % cdk synth
Traceback (most recent call last):
File "/Users//Desktop/pythoncdk/app.py", line 10, in
PythoncdkStack(app, "PythoncdkStack",
File "/Users/Desktop/pythoncdk/.venv/lib/python3.11/site-packages/jsii/_runtime.py", line 118, in __call__
inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users//Desktop/pythoncdk/pythoncdk/pythoncdk_stack.py", line 52, in __init__
task_definition.add_volume(volume)
TypeError: TaskDefinition.add_volume() takes 1 positional argument but 2 were given
```
### Reproduction Steps
Use the code below to reproduce the same:
```
from aws_cdk import (
# Duration,
Stack,
Size,
aws_rds as rds,
# aws_sqs as sqs,
aws_ec2 as ec2,
aws_ecs as ecs,
aws_appconfig as aws_appconfig,
)
from constructs import Construct
class PythoncdkStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# The code that defines your stack goes here
cluster = ecs.Cluster(self, 'cluster')
task_definition = ecs.FargateTaskDefinition(self, "TaskDef")
container = task_definition.add_container("web",
image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
port_mappings=[ecs.PortMapping(
container_port=80,
protocol=ecs.Protocol.TCP
)]
)
volume = ecs.ServiceManagedVolume(self, "EBSVolume",
name="ebs1",
managed_ebs_volume=ecs.ServiceManagedEBSVolumeConfiguration(
size=Size.gibibytes(15),
volume_type=ec2.EbsDeviceVolumeType.GP3,
file_system_type=ecs.FileSystemType.XFS,
tag_specifications=[ecs.EBSTagSpecification(
tags={
"purpose": "production"
},
propagate_tags=ecs.EbsPropagatedTagSource.SERVICE
)]
)
)
volume.mount_in(container,
container_path="/var/lib",
read_only=False
)
task_definition.add_volume(volume)
```
### Possible Solution
NA
### Additional Information/Context
NA
### CDK CLI Version
2.133.0 (build dcc1e75)
### Framework Version
aws-cdk-lib==2.133.0 constructs>=10.0.0,<11.0.0
### Node.js Version
v20.0.0
### OS
MacOs
### Language
Python
### Language Version
Python 3.11.7
### Other information
NA
Contributor guide
Research direction
Start with the ecs.TaskDefinition.add_volume entry point and compare the Python signature with the TypeScript usage shown in the report. Reproduce the call with the provided Python example, then verify that the method accepts the ServiceManagedVolume and that cdk synth produces a template containing the volume without a TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100