The Sceptre Template AWS CDK Example is out of date and does not support CDK Assets
Closed this issue · 2 comments
Subject of the issue
The Sceptre template AWS CDK example in https://github.com/Sceptre/sceptre/blob/master/docs/_source/docs/templates.rst is out of date, as it is for AWS CDK v1 rather than the current v2 and it does not support CDK stacks that require assets (constructs that create CloudFormation custom resources for example).
Your environment
- version of sceptre
3.2.0
- version of python
3.8.8
- which OS/distro:
Windows 10
- AWS CDK version:
2.51.1
Steps to reproduce
Use the following code with the current AWS CDK example. The BucketDeployment
construct creates a custom CloudFormation resource:
s3_bucket = s3.Bucket(self,
"S3Bucket",
bucket_name=sceptre_user_data['BucketName']
)
cdk.aws_s3_deployment.BucketDeployment(self,
"S3Deployment",
sources=[cdk.aws_s3_deployment.Source.data(
'object-key.txt', 'hello, world!')],
destination_bucket=s3_bucket
)
Expected behaviour
The CDK stack should be deployed successfully,
Actual behaviour
sceptre launch
fails with the following error:
ImportError: cannot import name 'core' from 'aws_cdk'
Once the example code has been refactored for CDK v2.x sceptre launch
fails with the following error:
[2022-11-23 16:52:08] - dev/cdk/s3/s3-original S3DeploymentAwsCliLayer8AAFE44F AWS::Lambda::LayerVersion CREATE_FAILED Error occurred while GetObject. S3 Error Code: NoSuchKey. S3 Error Message: The specified key does not exist. (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: 370f2978-891f-428d-921e-1f7116bacc19; Proxy: null)
This is due to the CDK assets for the CloudFormation custom resource not having been published.
Solution
I have an AWS CDK v2 example for Sceptre that published the CDK assets and I am happy to raise a PR to update the current example with it.
Hey @X-Guardian that's interesting. Yeah, historically, any cdk resources that included assets (like lambdas) we're not compatible with Sceptre considering how Sceptre just wants a template and doesn't actually know anything about "assets".
I'd definitely be interested in seeing a PR. We can discuss from there. Are you on the Sceptre slack channel? Most of us Sceptre devs hang around there.
Hi @jfalkenstein, my example uses cdk-assets to publish the assets. I'll raise a PR for you to look at.