class Source
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.S3.Deployment.Source |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awss3deployment#Source |
![]() | software.amazon.awscdk.services.s3.deployment.Source |
![]() | aws_cdk.aws_s3_deployment.Source |
![]() | aws-cdk-lib » aws_s3_deployment » Source |
Specifies bucket deployment source.
Usage:
Source.bucket(bucket, key)
Source.asset('/local/path/to/directory')
Source.asset('/local/path/to/a/file.zip')
Source.data('hello/world/file.txt', 'Hello, world!')
Source.jsonData('config.json', { baz: topic.topicArn })
Source.yamlData('config.yaml', { baz: topic.topicArn })
Example
declare const destinationBucket: s3.Bucket;
const deployment = new s3deploy.BucketDeployment(this, 'DeployFiles', {
sources: [s3deploy.Source.asset(path.join(__dirname, 'source-files'))],
destinationBucket,
});
deployment.handlerRole.addToPolicy(
new iam.PolicyStatement({
actions: ['kms:Decrypt', 'kms:DescribeKey'],
effect: iam.Effect.ALLOW,
resources: ['<encryption key ARN>'],
}),
);
Methods
Name | Description |
---|---|
static asset(path, options?) | Uses a local asset as the deployment source. |
static bucket(bucket, zipObjectKey) | Uses a .zip file stored in an S3 bucket as the source for the destination bucket contents. |
static data(objectKey, data) | Deploys an object with the specified string contents into the bucket. |
static json | Deploys an object with the specified JSON object into the bucket. |
static yaml | Deploys an object with the specified JSON object formatted as YAML into the bucket. |
static asset(path, options?)
public static asset(path: string, options?: AssetOptions): ISource
Parameters
- path
string
— The path to a local .zip file or a directory. - options
Asset
Options
Returns
Uses a local asset as the deployment source.
If the local asset is a .zip archive, make sure you trust the producer of the archive.
static bucket(bucket, zipObjectKey)
public static bucket(bucket: IBucket, zipObjectKey: string): ISource
Parameters
- bucket
IBucket
— The S3 Bucket. - zipObjectKey
string
— The S3 object key of the zip file with contents.
Returns
Uses a .zip file stored in an S3 bucket as the source for the destination bucket contents.
Make sure you trust the producer of the archive.
If the bucket
parameter is an "out-of-app" reference "imported" via static methods such
as s3.Bucket.fromBucketName
, be cautious about the bucket's encryption key. In general,
CDK does not query for additional properties of imported constructs at synthesis time.
For example, for a bucket created from s3.Bucket.fromBucketName
, CDK does not know
its IBucket.encryptionKey
property, and therefore will NOT give KMS permissions to the
Lambda execution role of the BucketDeployment
construct. If you want the
kms:Decrypt
and kms:DescribeKey
permissions on the bucket's encryption key
to be added automatically, reference the imported bucket via s3.Bucket.fromBucketAttributes
and pass in the encryptionKey
attribute explicitly.
Example
declare const destinationBucket: s3.Bucket;
const sourceBucket = s3.Bucket.fromBucketAttributes(this, 'SourceBucket', {
bucketArn: 'arn:aws:s3:::my-source-bucket-name',
encryptionKey: kms.Key.fromKeyArn(
this,
'SourceBucketEncryptionKey',
'arn:aws:kms:us-east-1:123456789012:key/<key-id>'
),
});
const deployment = new s3deploy.BucketDeployment(this, 'DeployFiles', {
sources: [s3deploy.Source.bucket(sourceBucket, 'source.zip')],
destinationBucket,
});
static data(objectKey, data)
public static data(objectKey: string, data: string): ISource
Parameters
- objectKey
string
— The destination S3 object key (relative to the root of the S3 deployment). - data
string
— The data to be stored in the object.
Returns
Deploys an object with the specified string contents into the bucket.
The
content can include deploy-time values (such as snsTopic.topicArn
) that
will get resolved only during deployment.
To store a JSON object use Source.jsonData()
.
To store YAML content use Source.yamlData()
.
static jsonData(objectKey, obj)
public static jsonData(objectKey: string, obj: any): ISource
Parameters
- objectKey
string
— The destination S3 object key (relative to the root of the S3 deployment). - obj
any
— A JSON object.
Returns
Deploys an object with the specified JSON object into the bucket.
The
object can include deploy-time values (such as snsTopic.topicArn
) that
will get resolved only during deployment.
static yamlData(objectKey, obj)
public static yamlData(objectKey: string, obj: any): ISource
Parameters
- objectKey
string
— The destination S3 object key (relative to the root of the S3 deployment). - obj
any
— A JSON object.
Returns
Deploys an object with the specified JSON object formatted as YAML into the bucket.
The object can include deploy-time values (such as snsTopic.topicArn
) that
will get resolved only during deployment.