-
Notifications
You must be signed in to change notification settings - Fork 4k
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_s3_assets): unable to define bundling with local (python) #17928
Comments
Can you try: @jsii.implements(ILocalBundling)
class JinjaLocalBundling()
def try_bundle(...) and then pass the instance of this class to JinjaBundling = BundlingOptions(
local=JinjaLocalBundling(),
... |
Thanks for the suggestion, but that doesn't seem to work for me... @jsii.implements(ILocalBundling)
class JinjaLocalBundling(ILocalBundling):
def try_bundle(self, output_dir, options, *args, **kwargs) -> bool:
print("Local Jinja2 Render:", self, output_dir, options, args, kwargs)
return False
JinjaBundling = BundlingOptions(
local=JinjaLocalBundling(),
image=DockerImage.from_registry("python3"),
command=["python3 -m pip install jinja2"]
) Within Stack class: asset = Asset(self, "ConfigureBundle", path=os.path.join(dirname, "configure.sh"),
bundling=JinjaBundling) Result of
It seems that JSII wants to convert the Again, the documentation needs to have a valid example. |
Try replacing: @jsii.implements(ILocalBundling)
class JinjaLocalBundling(ILocalBundling): with @jsii.implements(ILocalBundling)
class JinjaLocalBundling: ? This should be the syntax, based on the tests here: https://github.com/aws/jsii/blob/main/packages/%40jsii/python-runtime/tests/test_compliance.py#L172 |
For Python, interface implementation needs to be written as `@jsii.implements(Iface)`. Also add a check that people don't put functions in object literals. Fixes aws/aws-cdk#17928
For Python, interface implementation needs to be written as `@jsii.implements(Iface)`. Also add a check that people don't put functions in object literals. Fixes aws/aws-cdk#17928 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
|
@rix0rrr the def try_bundle(self, output_dir, *, image, entrypoint=None, command=None, volumes=None, environment=None, workingDirectory=None, user=None, local=None, outputType=None, securityOpt=None, network=None): Per my test and TypeScript documentation, it should be: def try_bundle(self, output_dir, options): Should I open a separate issue, or would you like to reopen this one? Full working example: import aws_cdk.aws_s3_assets as assets
import jsii
from aws_cdk import BundlingOptions, DockerImage, ILocalBundling
@jsii.implements(ILocalBundling)
class MyBundle:
def try_bundle(self, output_dir, options):
can_run_locally = True # replace with actual logic
if can_run_locally:
# perform local bundling here
return True
return False
assets.Asset(
self, "BundledAsset",
path=str(pathlib.Path(__file__).parent.parent.joinpath("docs").resolve()),
bundling=BundlingOptions(
local=MyBundle(),
# Docker bundling fallback
image=DockerImage.from_registry("alpine"),
entrypoint=["/bin/sh", "-c"],
command=["bundle"]
)
) cc: @heitorlessa |
link to reference doc page
https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_s3_assets/README.html#asset-bundling
Describe your issue?
The documentation has an example which is not syntactically correct for Python:
The value for 'bundling' isn't correct Python code. You can't define a function in the middle of a dictionary.
I've attempted to determine how to correctly define this value, but haven't been able to come up with the correct syntax. Based on the documentation, specific types are expected, so I tried constructing those types ahead of time:
Then, including it in the Asset creation:
This results in an error:
TypeError: Don't know how to convert object to JSON: <class 'test_app.test_stack.JinjaLocalBundling'>
There is very little documentation on how to do this correctly. Can someone demonstrate the correct way to use the
bundling
option for Asset definitions?Overall Goal: I want to render a script to be executed as part of the EC2 User Data by replacing variables in the script with values from the stack. For example, I have a script which syncs data from an S3 bucket, but the S3 bucket name needs to be injected into the script. Something like this to replace
{{ bucketname }}
with the bucket defined by the CDK app:If there is an easier way to do this, please let me know. (but also fix the doc since it really doesn't work)
Thanks!!
The text was updated successfully, but these errors were encountered: