flaviostutz / flaviostutz/cdk-practical-constructs

Feature Request: Deployment S3 bucket

Open
#17 6 comments 0 reactions 1 assignee Claimed by @MarcioMeier View on GitHub
enhancement
Dominant language
TypeScript
Stars
7
Forks
7
PR merge metrics
No merged PRs in 30d

Description

## Problem being solved
Deploying any kind of source code into AWS S3, such as react apps.

## Proposal
We create an S3 bucket for the deployment and upload the code from given path to it.

I thought on something like this codesnippet:
```ts
import { Construct } from 'constructs';
import { RemovalPolicy } from 'aws-cdk-lib';
import { Bucket, BlockPublicAccess, BucketProps } from 'aws-cdk-lib/aws-s3';
import { BucketDeployment, Source, BucketDeploymentProps } from 'aws-cdk-lib/aws-s3-deployment';

export class S3Bucket extends Construct {
public readonly bucket: Bucket;

constructor(scope: Construct, id: string, props: BucketProps) {
super(scope, id, props);

this.bucket = new Bucket(this, id, {
versioned: false,
bucketName: props.bucketName,
publicReadAccess: false,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
enforceSSL: true,
minimumTLSVersion: 1.2,
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
...props,
});
}
}

type S3BucketDeploymentProps = {
bucketConfig: BucketProps;
deploymentConfig: Omit;
};

export class S3BucketDeployment extends Construct {
constructor(scope: Construct, id: string, props: S3BucketDeploymentProps) {
super(scope, id, props);

const bucket = new S3Bucket(this, ${id}-bucket, props.bucketConfig);

new BucketDeployment(this, ${id}-bucket-deployment, {
sources: [Source.asset('./dist')],
destinationBucket: bucket,
...props.deploymentConfig,
});
}
}
```

It still needs refinement over the default props/polciies, etc..

Further reading:
- [AWS S3 Bucket lib](https://github.com/aws/aws-cdk/tree/main/packages/aws-cdk-lib/aws-s3)
- [AWS S3 Bucket deployment lib](https://github.com/aws/aws-cdk/tree/main/packages/aws-cdk-lib/aws-s3-deployment)

## Out of scope
- Cloudfront distributions

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.