aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.51k stars 3.85k forks source link

Support for Docker Image Assets in Service Catalog Product Stacks #31297

Open dannysteenman opened 1 week ago

dannysteenman commented 1 week ago

Describe the feature

Currently, when trying to use Docker image assets within a Service Catalog product stack, we encounter the following error:

Error: Service Catalog Product Stacks cannot use Assets
at ProductStackSynthesizer.addDockerImageAsset

Use Case

We need to deploy a lambda function as a docker container since the packages required more storage than a lambda layer supports.

Proposed Solution

In the api docs there's an example of regular assets that are supported: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_servicecatalog-readme.html#using-assets-in-your-product-stack

it would be nice to also support docker image assets.

Other Information

If you know of a workaround, that would be great!

Acknowledgements

CDK version used

2.155.0

Environment details (OS name and version, etc.)

macos

pahud commented 1 week ago

Thank you! Can you share some code snippets to help us get more context about it?

dannysteenman commented 1 week ago

sure:

    const portfolio = new Portfolio(this, 'rPortfolio', {
      displayName: 'portfolio',
      environment: Environment[process.env.STAGE?.toUpperCase() as keyof typeof Environment],
      managedResource: true,
      providerName: TEAM_NAME,
      shareTargetType: PortfolioShareTargetType.ALL,
    });

new lambda.DockerImageFunction(this, 'lamdaDockerFunction', {
      code: lambda.DockerImageCode.fromImageAsset(
        path.join(LAMBDA_PYTHON_DIRECTORY, 'path_to_source_containing_asset'),
        {
          platform: assets.Platform.LINUX_AMD64,
        },
      ),
      memorySize: 512,
      timeout: cdk.Duration.seconds(120),
      logRetention: logs.RetentionDays.ONE_YEAR,
    });

DummyProductStack extends servicecatalog.ProductStack

   const dummyProductStack = new DummyProductStack(this, 'DummyProductStack', {
      productMonitorRoleArn: rolearn,
      assetBucket: s3.Bucket.fromBucketName(this, 'assetbucket', this.node.tryGetContext('asset-bucket')),
    });
const dummyCfnProduct = new servicecatalog.CloudFormationProduct(this, 'DummyProduct', {
      owner: TEAM_NAME,
      distributor: TEAM_NAME,
      description: '...',
      productVersions: [
        {
          productVersionName: getProductVersion(),
          cloudFormationTemplate: servicecatalog.CloudFormationTemplate.fromProductStack(dummyProductStack),
        },
      ],
      ....

 portfolio.portfolio.addProduct(dummyCfnProduct);