in src/index.ts [205:253]
private _addFileAsset(asset: FileAssetSource, overrideBucketname?: string): FileAssetLocation {
assertNotNull(this.stack, ERR_MSG_CALL_BIND_FIRST);
assertNotNull(this.bucketName, 'The bucketName is null');
validateFileAssetSource(asset);
const bucketName = overrideBucketname ?? this.bucketName;
const objectKey = this.fileAssetPrefix + asset.sourceHash + (asset.packaging === FileAssetPackaging.ZIP_DIRECTORY ? '.zip' : '');
const destinations: { [id: string]: cxschema.FileDestination } = {};
if (this.fileAssetRegionSet?.length && bucketName.includes(REGION_PLACEHOLDER)) {
for (const region of this.fileAssetRegionSet.map(r => r.trim())) {
if (!region) { continue; }
destinations[region] = {
bucketName: replaceAll(bucketName, REGION_PLACEHOLDER, region),
objectKey,
region,
assumeRoleArn: this.fileAssetPublishingRoleArn,
};
}
} else {
destinations[this.manifestEnvName] = {
bucketName,
objectKey,
region: resolvedOr(this.stack.region, trim(head(this.fileAssetRegionSet))),
assumeRoleArn: this.fileAssetPublishingRoleArn,
};
}
// Add to manifest
this.files[asset.sourceHash] = {
source: {
path: asset.fileName,
packaging: asset.packaging,
},
destinations,
};
const { region, urlSuffix } = stackLocationOrInstrinsics(this.stack);
const httpUrl = cfnify(`https://s3.${region}.${urlSuffix}/${bucketName}/${objectKey}`);
const s3ObjectUrl = cfnify(`s3://${bucketName}/${objectKey}`);
// Return CFN expression
return {
bucketName: cfnify(bucketName),
objectKey,
httpUrl,
s3ObjectUrl,
};
}