How to use the @aws-cdk/aws-s3.Bucket function in @aws-cdk/aws-s3

To help you get started, we’ve selected a few @aws-cdk/aws-s3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github seagull-js / seagull / packages / deploy-aws / src / seagull_stack.ts View on Github external
addS3(bucketName: string, role?: IAM.IPrincipal, keepBucket = true) {
    const removalPolicy = keepBucket ? RemPolicy.Orphan : RemPolicy.Destroy
    const s3Props = { bucketName, removalPolicy }
    const bucket = new S3.Bucket(this, `${this.id}-${bucketName}`, s3Props)
    // tslint:disable-next-line:no-unused-expression
    role && bucket.grantReadWrite(role)
    return bucket
  }
github josephluck / internote / ui / deploy / index.ts View on Github external
async function buildMyStack(scope: cdk.Construct, id: string, props: {}) {
  const stack = new cdk.Stack(scope, id, props);

  // TODO: inject environment variables
  // should be via SSM. See here:
  // https://docs.aws.amazon.com/cdk/latest/guide/get_ssm_value.html
  await execute("./node_modules/.bin/next", ["build"]);

  const manifest = await getBuildManifest();
  const staticPages = Object.values(manifest.pages.html);

  const bucket = new s3.Bucket(scope, `${id}-bucket`, {
    publicReadAccess: true
  });
  new s3Upload.BucketDeployment(stack, `${id}-s3-static-pages`, {
    // TODO: these files might already be prefixed with `pages/${page}`? This will need to be removed if so.
    sources: staticPages.map(page =>
      s3Upload.Source.asset(`./.next/serverless/${page}`)
    ),
    destinationBucket: bucket,
    destinationKeyPrefix: "static-pages"
  });
  new s3Upload.BucketDeployment(stack, `${id}-s3-next-static-files`, {
    sources: [s3Upload.Source.asset("./.next/static")],
    destinationBucket: bucket,
    destinationKeyPrefix: "_next/static"
  });
  new s3Upload.BucketDeployment(stack, `${id}-s3-public-files`, {
github nathanpeck / screenshot-service / app.3.js View on Github external
constructor(parent, id, props) {
    super(parent, id, props);

    // Create a network for the application to run in
    this.vpc = new ec2.VpcNetwork(this, 'vpc', {
      maxAZs: 2,
      natGateways: 1
    });

    // Create an ECS cluster
    this.cluster = new ecs.Cluster(this, 'cluster', {
      vpc: this.vpc
    });

    // Create S3 bucket
    this.screenshotBucket = new s3.Bucket(this, 'screenshot-bucket', {
      publicReadAccess: true
    });

    // Create queue
    this.screenshotQueue = new sqs.Queue(this, 'screenshot-queue');

    // Create DynamoDB table
    this.screenshotTable = new dynamodb.Table(this, 'screenshots', {
      partitionKey: { name: 'id', type: dynamodb.AttributeType.String },
      billingMode: dynamodb.BillingMode.PayPerRequest
    });
  }
}
github aws / aws-cdk / packages / @aws-cdk / aws-glue / lib / table.ts View on Github external
let encryptionKey: kms.IKey | undefined;
  if (encryption === TableEncryption.CLIENT_SIDE_KMS && props.encryptionKey === undefined) {
    // CSE-KMS should behave the same as SSE-KMS - use the provided key or create one automatically
    // Since Bucket only knows about SSE, we repeat the logic for CSE-KMS at the Table level.
    encryptionKey = new kms.Key(table, 'Key');
  } else {
    encryptionKey = props.encryptionKey;
  }

  // create the bucket if none was provided
  if (!bucket) {
    if (encryption === TableEncryption.CLIENT_SIDE_KMS) {
      bucket = new s3.Bucket(table, 'Bucket');
    } else {
      bucket = new s3.Bucket(table, 'Bucket', {
        encryption: encryptionMappings[encryption],
        encryptionKey
      });
      encryptionKey = bucket.encryptionKey;
    }
  }

  return {
    bucket,
    encryption,
    encryptionKey
  };
}
github aws / aws-cdk / packages / @aws-cdk / aws-glue / lib / table.ts View on Github external
throw new Error('you can not specify encryption settings if you also provide a bucket');
  }

  let encryptionKey: kms.IKey | undefined;
  if (encryption === TableEncryption.CLIENT_SIDE_KMS && props.encryptionKey === undefined) {
    // CSE-KMS should behave the same as SSE-KMS - use the provided key or create one automatically
    // Since Bucket only knows about SSE, we repeat the logic for CSE-KMS at the Table level.
    encryptionKey = new kms.Key(table, 'Key');
  } else {
    encryptionKey = props.encryptionKey;
  }

  // create the bucket if none was provided
  if (!bucket) {
    if (encryption === TableEncryption.CLIENT_SIDE_KMS) {
      bucket = new s3.Bucket(table, 'Bucket');
    } else {
      bucket = new s3.Bucket(table, 'Bucket', {
        encryption: encryptionMappings[encryption],
        encryptionKey
      });
      encryptionKey = bucket.encryptionKey;
    }
  }

  return {
    bucket,
    encryption,
    encryptionKey
  };
}
github seagull-js / seagull / packages / deploy / src / lib / cdk / stack.ts View on Github external
private addS3() {
    const s3Props = { bucketName: this.s3Name }
    const bucket = new S3.Bucket(this, `${this.appName}-item-bucket`, s3Props)
    bucket.grantReadWrite(this.role)
  }
github cloudcomponents / cdk-components / packages / cdk-static-website / src / website-bucket.ts View on Github external
constructor(scope: Construct, id: string, props: WebsiteBucketProps = {}) {
        super(scope, id);

        const {
            bucketName,
            removalPolicy = RemovalPolicy.RETAIN,
            disableUpload = false,
            source,
            websiteIndexDocument,
            websiteErrorDocument,
        } = props;

        const bucket = new Bucket(this, 'WebsiteBucket', {
            bucketName,
            removalPolicy,
            websiteIndexDocument: websiteIndexDocument || 'index.html',
            websiteErrorDocument: websiteErrorDocument || 'error.html',
        });

        const originId = new CfnCloudFrontOriginAccessIdentity(
            this,
            'OriginAccessIdentity',
            {
                cloudFrontOriginAccessIdentityConfig: {
                    comment: `CloudFront OriginAccessIdentity for ${bucket.bucketName}`,
                },
            },
        );
github jeshan / scale-your-cloudformation / lib / cdk-stack.js View on Github external
constructor(scope) {
        super(scope, 'scale-your-cloudformation');

        const domainName = 'scaleyourcloudformation.com';
        const cert = new Certificate(this, 'cert', {
            domainName,
            validationMethod: ValidationMethod.DNS,
        });

        const websiteBucket = new Bucket(this, 'WebsiteBucket', {
            domainName,
            removalPolicy: RemovalPolicy.DESTROY,
            websiteIndexDocument: 'index.html',
            websiteErrorDocument: 'error.html',
        });

        const originId = new CfnCloudFrontOriginAccessIdentity(
            this,
            'OriginAccessIdentity',
            {
                cloudFrontOriginAccessIdentityConfig: {
                    comment: `CloudFront OriginAccessIdentity for ${websiteBucket.bucketName}`,
                },
            },
        );
github aws / aws-cdk / packages / @aws-cdk / aws-codepipeline / lib / cross-region-support-stack.ts View on Github external
constructor(scope: cdk.Construct, id: string) {
    super(scope, id);

    const encryptionKey = new kms.Key(this, 'CrossRegionCodePipelineReplicationBucketEncryptionKey', {
      removalPolicy: cdk.RemovalPolicy.DESTROY,
    });
    const encryptionAlias = new AliasWithShorterGeneratedName(this, 'CrossRegionCodePipelineReplicationBucketEncryptionAlias', {
      targetKey: encryptionKey,
      aliasName: cdk.PhysicalName.GENERATE_IF_NEEDED,
      removalPolicy: cdk.RemovalPolicy.DESTROY,
    });
    this.replicationBucket = new s3.Bucket(this, 'CrossRegionCodePipelineReplicationBucket', {
      bucketName: cdk.PhysicalName.GENERATE_IF_NEEDED,
      encryptionKey: encryptionAlias,
    });
  }
}

@aws-cdk/aws-s3

The CDK Construct Library for AWS::S3

Apache-2.0
Latest version published 11 months ago

Package Health Score

70 / 100
Full package analysis