Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To upload a zip file to S3 using CDK, follow these steps:

  1. First, import the necessary modules:
import * as s3 from '@aws-cdk/aws-s3';
import * as s3deploy from '@aws-cdk/aws-s3-deployment';
  1. Create an S3 bucket:
const myBucket = new s3.Bucket(this, 'MyBucket');
  1. Define the local path of the zip file:
const localPath = path.join(__dirname, '../myapp.zip');
  1. Upload the zip file to the S3 bucket:
new s3deploy.BucketDeployment(this, 'DeployFiles', {
   sources: [s3deploy.Source.asset(localPath)], 
   destinationBucket: myBucket 
});
  1. Deploy the CDK stack:
cdk deploy

This will create an S3 bucket and upload the zip file to it.