aws / aws/aws-cdk

servicecatalog: Product containing BucketDeployment: AWS CLI Layer asset stored in wrong bucket

Open
#25,733 10 comments 5 reactions 0 assignees View on GitHub
@aws-cdk/aws-servicecatalog bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### Describe the bug

The product is made with the `fromProductStack` functionality and it contains the `BucketDeployment` Resource.
When trying to launch this product in the target account it fails to deploy because one part of the error:
```
Error occurred while GetObject. S3 Error Code: NoSuchKey. S3 Error Message: The specified key does not exist.
```
The object is correctly referenced in the template, however the assets bucket does not contain the corresponding .zip file.
After investigation the file was found in the standard cdk bootstrapping bucket (cdk-assets).
When the .zip file is copied to the product assets bucket then the product launches correctly.
This asset contains the AWSCliLayer files needed for the BucketDeployment.

### Expected Behavior

The required assets is stored in the product stack assets bucket and the product launches.

### Current Behavior

The required asset is stored in the cdk bootstrapping bucket and while launching of the product the product cannot find the asset in the assets bucket, because obviously this file is missing there.

### Reproduction Steps

Full minimal example:

```typescript
import * as cdk from 'aws-cdk-lib'
import { aws_s3 } from 'aws-cdk-lib'
import { Construct } from 'constructs'
import { CloudFormationTemplate, Portfolio } from 'aws-cdk-lib/aws-servicecatalog'
import { BlockPublicAccess, Bucket } from 'aws-cdk-lib/aws-s3'
import { BucketDeployment } from 'aws-cdk-lib/aws-s3-deployment'

export class ServiceCatalogPortfolioStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)

const portfolio = new Portfolio(this, 'Portfolio', {
displayName: 'MyPortfolio',
providerName: 'MyTeam',
})

const assetsBucket = new Bucket(this, 'AssetsBucket', {
bucketName: 'asset-bucket-my-fancy-unique-name',
})

const product = new cdk.aws_servicecatalog.CloudFormationProduct(this, 'DemoAppProduct', {
productName: 'DemoAppProduct',
owner: 'MrBug',
productVersions: [
{
productVersionName: 'v2',
cloudFormationTemplate: CloudFormationTemplate.fromProductStack(
new AssetBucketDemoProductStack(this, 'AssetBucketDemoStack', { assetBucket: assetsBucket }),
),
},
],
})

portfolio.addProduct(product)
portfolio.shareWithAccount('targetAccount')
}
}

class AssetBucketDemoProductStack extends cdk.aws_servicecatalog.ProductStack {
constructor(scope: Construct, id: string, props?: cdk.aws_servicecatalog.ProductStackProps) {
super(scope, id, props)

const frontendBucket = new aws_s3.Bucket(this, 'FrontendDistributionBucket', {
publicReadAccess: false,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true,
})

const bucketDeployment = new BucketDeployment(this, 'FrontendBucketDeployment', {
sources: [cdk.aws_s3_deployment.Source.asset('./dist')],
destinationBucket: frontendBucket,
})
}
}
```

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.80.0

### Framework Version

_No response_

### Node.js Version

18.15.0

### OS

Windows

### Language

Typescript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the minimal TypeScript reproduction using CloudFormationProduct.fromProductStack, ProductStack, and BucketDeployment. Trace how the BucketDeployment AWS CLI Layer asset is referenced and stored during product asset handling. Done means the required .zip is present in the product assets bucket and the product launches successfully in the target account.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.