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

BucketDeployment: single files #24787

Open austinmw opened 1 year ago

austinmw commented 1 year ago

Describe the feature

Hi, I'd love to be able to deploy single files in addition to directories and zip files using BucketDeployment.

Use Case

Due to the directory structure of my codebase I'm not able to move all single files into a folder or zip prior to cdk deployment. Currently I'm working around this by using with TemporaryDirectory() as temp_dir: in my CDK stack and using this temp_dir as the s3_deployment.Source.asset, however, this feels like the wrong way to do things.

Proposed Solution

I assume there is a justification for not including this functionality originally, but it'd be great if it were added in some way.

Other Information

Essentially my project structure contains a CDK app and a python library. I'd like to be able to use poetry and the same pyproject.toml (with tool.poetry.group's) to install the dependencies for either.

Here's a shortened version of the directory structure:

├── Makefile
├── pyproject.toml
├── poetry.toml
├── poetry.lock
├── environment.yml
├── app.py
├── cdk.json
├── docs/
├── examples/
├── lifecycles/
├── src/mypythonlibrary/
├── sample_datasets/
├── stacks/
└── tests/

Ideally I would like the directories src, examples, and sample_datasets, as well as the single files Makefile, pyproject.toml, poetry.toml, poetry.lock, and environment.yml placed in my S3 bucket.

Acknowledgements

CDK version used

2.70.0 (build c13a0f1)

Environment details (OS name and version, etc.)

macOS Monterey 12.6.3

pahud commented 1 year ago

Thank you. I am making it p2 feature request now and any pull request or upvotes would be appreciated.

Styerp commented 1 year ago

You can use Source.data for single files:

import { App, Stack } from 'aws-cdk-lib/core'
import { Bucket } from "aws-cdk-lib/aws-s3"
import { BucketDeployment, Source } from "aws-cdk-lib/aws-s3-deployment"
import * as fs from "fs";
import * as path from "path";

const app = new App();
const stack = new Stack(app, "Stack");
const integBucket = new Bucket(stack, "Bucket");
new BucketDeployment(stack, "Deploy", {
    sources: [
        Source.data("Readme.md", fs.readFileSync(path.resolve(__dirname, "..", "README.md")).toString())
    ],
    destinationBucket: integBucket
})