DeployTimeSubstitutedFile
DeployTimeSubstitutedFile is an extension of BucketDeployment that allows users to upload individual files and specify to make substitutions in the file.
Example
import * as lambda from 'aws-cdk-lib/aws-lambda';
declare const myLambdaFunction: lambda.Function;
declare const destinationBucket: s3.Bucket;
//(Optional) if provided, the resulting processed file would be uploaded to the destinationBucket under the destinationKey name.
declare const destinationKey: string;
declare const role: iam.Role;
new s3deploy.DeployTimeSubstitutedFile(this, 'MyFile', {
source: 'my-file.yaml',
destinationKey: destinationKey,
destinationBucket: destinationBucket,
substitutions: {
variableName: myLambdaFunction.functionName,
},
role: role,
});
import aws_cdk.aws_lambda as lambda_
# my_lambda_function: lambda.Function
# destination_bucket: s3.Bucket
# (Optional) if provided, the resulting processed file would be uploaded to the destinationBucket under the destinationKey name.
# destination_key: str
# role: iam.Role
s3deploy.DeployTimeSubstitutedFile(self, "MyFile",
source="my-file.yaml",
destination_key=destination_key,
destination_bucket=destination_bucket,
substitutions={
"variable_name": my_lambda_function.function_name
},
role=role
)
import software.amazon.awscdk.services.lambda.*;
Function myLambdaFunction;
Bucket destinationBucket;
//(Optional) if provided, the resulting processed file would be uploaded to the destinationBucket under the destinationKey name.
String destinationKey;
Role role;
DeployTimeSubstitutedFile.Builder.create(this, "MyFile")
.source("my-file.yaml")
.destinationKey(destinationKey)
.destinationBucket(destinationBucket)
.substitutions(Map.of(
"variableName", myLambdaFunction.getFunctionName()))
.role(role)
.build();
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Lambda;
Function myLambdaFunction;
Bucket destinationBucket;
//(Optional) if provided, the resulting processed file would be uploaded to the destinationBucket under the destinationKey name.
string destinationKey;
Role role;
new DeployTimeSubstitutedFile(this, "MyFile", new DeployTimeSubstitutedFileProps {
Source = "my-file.yaml",
DestinationKey = destinationKey,
DestinationBucket = destinationBucket,
Substitutions = new Dictionary<string, string> {
{ "variableName", myLambdaFunction.FunctionName }
},
Role = role
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import lambda "github.com/aws/aws-cdk-go/awscdk"
var myLambdaFunction Function
var destinationBucket Bucket
//(Optional) if provided, the resulting processed file would be uploaded to the destinationBucket under the destinationKey name.
var destinationKey string
var role Role
s3deploy.NewDeployTimeSubstitutedFile(this, jsii.String("MyFile"), &DeployTimeSubstitutedFileProps{
Source: jsii.String("my-file.yaml"),
DestinationKey: destinationKey,
DestinationBucket: destinationBucket,
Substitutions: map[string]*string{
"variableName": myLambdaFunction.functionName,
},
Role: role,
})
Initializer
new DeployTimeSubstitutedFile(scope: Construct, id: string, props: DeployTimeSubstitutedFileProps)
DeployTimeSubstitutedFile(scope: Construct, id: str, props: DeployTimeSubstitutedFileProps)
new DeployTimeSubstitutedFile(Construct scope, String id, DeployTimeSubstitutedFileProps props)
new DeployTimeSubstitutedFile(Construct scope, string id, DeployTimeSubstitutedFileProps props)
NewDeployTimeSubstitutedFile(Scope Construct, Id *string, Props DeployTimeSubstitutedFileProps)
Construct Props
destinationBucketIBucketdestination_bucketIBucketdestinationBucketIBucketDestinationBucketIBucketDestinationBucketIBucketrequired#destinationKeyoptionalstringdestination_keyoptionalstrdestinationKeyoptionalStringDestinationKeyoptionalstringDestinationKeyoptional*string#Default: Fingerprint of the file content would be used as object key
Default: A role is automatically created
substitutions{ [key: string]: string }substitutionstyping.Mapping[str, str]substitutionsMap<String, String>SubstitutionsIDictionary<string, string>Substitutions*map[string]*stringrequired#Placeholders in the user's local file must be specified with double curly brackets and spaces. For example, if you use the key 'xxxx' in the file, it must be written as: {{ xxxx }} to be recognized by the construct as a substitution.
Properties
deployedBucketIBucketdeployed_bucketIBucketdeployedBucketIBucketDeployedBucketIBucketDeployedBucketIBucket#notes
If you want to reference the destination bucket in another construct and make sure the bucket deployment has happened before the next operation is started, pass the other construct a reference to deployment.deployedBucket.
Note that this only returns an immutable reference to the destination bucket. If sequenced access to the original destination bucket is required, you may add a dependency on the bucket deployment instead: otherResource.node.addDependency(deployment)
objectKeysstring[]object_keystyping.List[str]objectKeysList<String>ObjectKeysstring[]ObjectKeys*[]*string#notes
This returns a list of tokenized object keys for source files that are deployed to the bucket.
This can be useful when using BucketDeployment with extract set to false and you need to reference the object key that resides in the bucket for that zip source file somewhere else in your CDK application, such as in a CFN output.
For example, use Fn.select(0, myBucketDeployment.objectKeys) to reference the object key of the first source file in your bucket deployment.
objectVersionIdsstring[]object_version_idstyping.List[str]objectVersionIdsList<String>ObjectVersionIdsstring[]ObjectVersionIds*[]*string#PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#Methods
addSource(source: ISource): voiddef add_source(self, source: ISource) -> Nonepublic void addSource(ISource source)public void AddSource(ISource source)func AddSource(Source ISource)#example
declare const websiteBucket: s3.IBucket;
const deployment = new s3deploy.BucketDeployment(this, 'Deployment', {
sources: [s3deploy.Source.asset('./website-dist')],
destinationBucket: websiteBucket,
});
deployment.addSource(s3deploy.Source.asset('./another-asset'));
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.
1 parameter · returns
Parameters
mixinsmixinsmixinsmixinsMixins— The mixins to apply.
Returns: This construct for chaining