aws / aws/jsii

aws_s3_deployment: UserDefinedObjectMetadata does not work as documented

Open
#3,905 1 comment 0 reactions 0 assignees View on GitHub
bug effort/medium p2
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### Describe the bug

Hello, I'm trying to have user-defined metadata in an S3 Deployment using `UserDefinedObjectMetadata` however it doesn't seem to work. Details below.

### Expected Behavior

Successful synthetization of the stack where the S3 Deployment is implemented.

### Current Behavior

Stack is not synthesized due to a `TypeError`:

~~~
Traceback (most recent call last):
File "/home/cvmeq/cdk-project/app.py", line 10, in
CdkProjectStack(app, "CdkProjectStack",
File "/home/cvmeq/cdk-project/.venv/lib/python3.10/site-packages/jsii/_runtime.py", line 111, in __call__
inst = super().__call__(*args, **kwargs)
File "/home/cvmeq/cdk-project/cdk_project/cdk_project_stack.py", line 23, in __init__
metadata=s3deploy.UserDefinedObjectMetadata(A="1", b="2"), # user-defined metadata
TypeError: UserDefinedObjectMetadata.__init__() got an unexpected keyword argument 'A'

Subprocess exited with error 1
~~~

### Reproduction Steps

Create a Python project:

~~~
mkdir cdk-project
cd cdk-project
cdk init app --language python
source .venv/bin/activate
python -m pip install -r requirements.txt
~~~

No changes in the default `app.py` required. Change `cdk_project/cdk_project_stack.py` to match the following:

~~~python
from aws_cdk import (
Duration,
Stack,
aws_s3 as s3,
aws_s3_deployment as s3deploy
)
from constructs import Construct

class CdkProjectStack(Stack):

def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

website_bucket = s3.Bucket(self, "WebsiteBucket",
website_index_document="index.html",
public_read_access=True
)

s3deploy.BucketDeployment(self, "DeployWebsite",
sources=[s3deploy.Source.asset("./website-dist")],
destination_bucket=website_bucket,
destination_key_prefix="web/static", # optional prefix in destination bucket
metadata=s3deploy.UserDefinedObjectMetadata(A="1", b="2"), # user-defined metadata

# system-defined metadata
content_type="text/html",
content_language="en",
storage_class=s3deploy.StorageClass.INTELLIGENT_TIERING,
server_side_encryption=s3deploy.ServerSideEncryption.AES_256,
cache_control=[
s3deploy.CacheControl.set_public(),
s3deploy.CacheControl.max_age(Duration.hours(1))
],
access_control=s3.BucketAccessControl.BUCKET_OWNER_FULL_CONTROL
)
~~~

The code above was copied verbatim from the [documentation](https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_s3_deployment/UserDefinedObjectMetadata.html).

Now synthesize the stack to see the problem:

~~~
cdk synth CdkProjectStack
~~~

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.59.0 (build b24095d)

### Framework Version

_No response_

### Node.js Version

v16.18.0

### OS

Linux Ubuntu 20.04.2 LTS

### Language

Python

### Language Version

Python 3.10.6

### Other information

Python packages that are installed in the virtual environment:

~~~
Package Version
--------------------------------- --------
attrs 22.2.0
aws-cdk.asset-awscli-v1 2.2.49
aws-cdk.asset-kubectl-v20 2.1.1
aws-cdk.asset-node-proxy-agent-v5 2.0.38
aws-cdk-lib 2.59.0
cattrs 22.2.0
constructs 10.1.210
exceptiongroup 1.1.0
jsii 1.73.0
pip 22.2.1
publication 0.0.3
python-dateutil 2.8.2
setuptools 63.2.0
six 1.16.0
typeguard 2.13.3
typing_extensions 4.4.0
~~~

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure from cdk_project/cdk_project_stack.py with the listed aws-cdk-lib and jsii versions, then run cdk synth CdkProjectStack. Trace how UserDefinedObjectMetadata is exposed to Python and compare that API with the linked documentation. Done means the documented keyword arguments work during stack synthesis and the regression is covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.