Skip to content
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): add asset bundling functionality to aws_s3_deployment #27214

Open
1 of 2 tasks
myerscf opened this issue Sep 20, 2023 · 1 comment
Open
1 of 2 tasks

(aws_s3): add asset bundling functionality to aws_s3_deployment #27214

myerscf opened this issue Sep 20, 2023 · 1 comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@myerscf
Copy link

myerscf commented Sep 20, 2023

Describe the feature

Extend the functionality of S3 Assets - Asset Bundling functionality, to be able to build and bundle resources but pass them to a custom target, as an opposed to a CDK managed S3 bucket.

Use Case

Use this functionality in collaboration with other resources such as the S3 Deployment construct, in order to create robust deployment of application managed resources such as front end assets and media content.

Alternative Options:

  • Give the aws_s3_deployment construct a bundling parameter which could act the same as the aws_s3_assets.
  • Create a type of "Asset Bundling" construct, which could then be passed as a source to aws_s3_assets - the retroactively update

Proposed Solution

aws_s3_assets needs a bucket property, that will override its bundled destination target.

Update sources on aws_s3_deployment to be able to take an aws_s3_assets as a target. If it is passed a aws_s3_asset then it should set the bucket property for it, based in the bucket value of the deployment.

This implementation would not cause any BCs, as it would only take effect if the user overrides the bucket property. If omitted, aws_s3_assets would continue as normal to push to a CDK managed bucket.

Other Information

Scenario 1: Creating an asset and giving it to a BucketDeployment.

In this example giving the builtAsset to the BucketDeployment overrides the Assets new bucket property (done via setter when the deployment is constructed

const websiteBucket = new s3.Bucket(this, 'WebsiteBucket');

const builtAsset = new Asset(this, 'BundledAsset', {
  path: path.join(__dirname, 'website'),
  bundling: {
      command: [
          'npm build prod',
      ],
  },
});

const deployment = new s3deploy.BucketDeployment(this, 'DeployWebsite', {
  sources: [ builtAsset ],
  destinationBucket: websiteBucket,
  destinationKeyPrefix: 'web/static', // optional prefix in destination bucket
}); 

Scenario 2: Giving Asset a specified bucket.
In this example giving Asset a bucket, would put all built assets into the websiteBucket as opposed to the CDK managed one.

const websiteBucket = new s3.Bucket(this, 'WebsiteBucket');

const builtAsset = new Asset(this, 'BundledAsset', {
  path: path.join(__dirname, 'website'),
  bucket: websiteBucket
  bundling: {
      command: [
          'npm build prod',
      ],
  },
});

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.96.2

Environment details (OS name and version, etc.)

OSX Ventura 13.5.2

@myerscf myerscf added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2023
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Sep 20, 2023
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2023
@khushail
Copy link
Contributor

khushail commented Sep 20, 2023

Hi @myerscf , thanks for reaching out with this request. Yes, it would be a good addItion to have such prop in AssetProps or any other alternate provided.

@khushail khushail added p2 effort/medium Medium work item – several days of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants