From 996167bc7a3364b1b5f0c3d9d4251da2125b8d1d Mon Sep 17 00:00:00 2001 From: Ryan England Date: Tue, 14 Apr 2020 01:13:21 -0400 Subject: [PATCH 1/2] feat(aws-s3-asssets): add s3ObjectUrl property to asset closes #7221 Add s3ObjectUrl property. Rename s3Url to httpUrl to prevent confusion. Update integ.assets.refs.lit.ts and integ.assets.refs.lit.expected.json. Integration tests completed successfully. Shout out to Elad Ben-Israel for his guidance. --- packages/@aws-cdk/aws-s3-assets/README.md | 3 +- packages/@aws-cdk/aws-s3-assets/lib/asset.ts | 13 +++- .../test/integ.assets.refs.lit.expected.json | 60 +++++++++++++++---- .../test/integ.assets.refs.lit.ts | 3 +- packages/@aws-cdk/core/lib/assets.ts | 2 +- packages/@aws-cdk/core/lib/stack.ts | 4 +- 6 files changed, 67 insertions(+), 18 deletions(-) diff --git a/packages/@aws-cdk/aws-s3-assets/README.md b/packages/@aws-cdk/aws-s3-assets/README.md index 44d054c962eab..e696bebca6e6a 100644 --- a/packages/@aws-cdk/aws-s3-assets/README.md +++ b/packages/@aws-cdk/aws-s3-assets/README.md @@ -40,9 +40,10 @@ to an S3 bucket during deployment. `Asset` constructs expose the following deploy-time attributes: + * `httpUrl` - the HTTP URL of the asset (i.e. https://s3.us-east-1.amazonaws.com/mybucket/mykey.zip) * `s3BucketName` - the name of the assets S3 bucket. * `s3ObjectKey` - the S3 object key of the asset file (whether it's a file or a zip archive) - * `s3Url` - the S3 URL of the asset (i.e. https://s3.us-east-1.amazonaws.com/mybucket/mykey.zip) + * `s3UrlObject` - the S3 URL of the asset (i.e. s3://mybucket/mykey.zip) In the following example, the various asset attributes are exported as stack outputs: diff --git a/packages/@aws-cdk/aws-s3-assets/lib/asset.ts b/packages/@aws-cdk/aws-s3-assets/lib/asset.ts index d2b7712564e03..0385e335ee4f9 100644 --- a/packages/@aws-cdk/aws-s3-assets/lib/asset.ts +++ b/packages/@aws-cdk/aws-s3-assets/lib/asset.ts @@ -51,6 +51,12 @@ export interface AssetProps extends AssetOptions { * and then can be referenced within a CDK application. */ export class Asset extends cdk.Construct implements assets.IAsset { + /** + * Attribute which represents the HTTP URL of this asset. + * @example https://s3.us-west-1.amazonaws.com/bucket/key + */ + public readonly httpUrl: string; + /** * Attribute that represents the name of the bucket this asset exists in. */ @@ -63,9 +69,9 @@ export class Asset extends cdk.Construct implements assets.IAsset { /** * Attribute which represents the S3 URL of this asset. - * @example https://s3.us-west-1.amazonaws.com/bucket/key + * @example s3://bucket/key */ - public readonly s3Url: string; + public readonly s3ObjectUrl: string; /** * The path to the asset (stringinfied token). @@ -116,9 +122,10 @@ export class Asset extends cdk.Construct implements assets.IAsset { fileName: staging.stagedPath }); + this.httpUrl = location.httpUrl; this.s3BucketName = location.bucketName; this.s3ObjectKey = location.objectKey; - this.s3Url = location.s3Url; + this.s3ObjectUrl = `s3://${this.s3BucketName}/${this.s3ObjectKey}`; this.bucket = s3.Bucket.fromBucketName(this, 'AssetBucket', this.s3BucketName); diff --git a/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json index 6b25a2e5cdc63..dcd5cc5a123d3 100644 --- a/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json +++ b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json @@ -14,6 +14,54 @@ } }, "Outputs": { + "HTTPURL": { + "Value": { + "Fn::Join": [ + "", + [ + "https://s3.", + { + "Ref": "AWS::Region" + }, + ".", + { + "Ref": "AWS::URLSuffix" + }, + "/", + { + "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3Bucket50B5A10B" + }, + "/", + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3VersionKey1F7D75F9" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3VersionKey1F7D75F9" + } + ] + } + ] + } + ] + ] + } + }, "S3BucketName": { "Value": { "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3Bucket50B5A10B" @@ -54,20 +102,12 @@ ] } }, - "S3URL": { + "S3ObjectUrl": { "Value": { "Fn::Join": [ "", [ - "https://s3.", - { - "Ref": "AWS::Region" - }, - ".", - { - "Ref": "AWS::URLSuffix" - }, - "/", + "s3://", { "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3Bucket50B5A10B" }, diff --git a/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts index b7311353f8de1..94185dc587117 100644 --- a/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts +++ b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts @@ -12,9 +12,10 @@ class TestStack extends cdk.Stack { path: path.join(__dirname, 'sample-asset-directory') }); + new cdk.CfnOutput(this, 'HTTPURL', { value: asset.httpUrl }); new cdk.CfnOutput(this, 'S3BucketName', { value: asset.s3BucketName }); new cdk.CfnOutput(this, 'S3ObjectKey', { value: asset.s3ObjectKey }); - new cdk.CfnOutput(this, 'S3URL', { value: asset.s3Url }); + new cdk.CfnOutput(this, 'S3ObjectUrl', { value: asset.s3ObjectUrl }); /// !hide // we need at least one resource diff --git a/packages/@aws-cdk/core/lib/assets.ts b/packages/@aws-cdk/core/lib/assets.ts index a397a8aa6624a..7222d08ca86fb 100644 --- a/packages/@aws-cdk/core/lib/assets.ts +++ b/packages/@aws-cdk/core/lib/assets.ts @@ -114,7 +114,7 @@ export interface FileAssetLocation { * * @example https://s3-us-east-1.amazonaws.com/mybucket/myobject */ - readonly s3Url: string; + readonly httpUrl: string; } /** diff --git a/packages/@aws-cdk/core/lib/stack.ts b/packages/@aws-cdk/core/lib/stack.ts index 104dd362b4196..6ee59eedda220 100644 --- a/packages/@aws-cdk/core/lib/stack.ts +++ b/packages/@aws-cdk/core/lib/stack.ts @@ -563,9 +563,9 @@ export class Stack extends Construct implements ITaggable { const s3Filename = Fn.select(1, Fn.split(cxapi.ASSET_PREFIX_SEPARATOR, encodedKey)); const objectKey = `${s3Prefix}${s3Filename}`; - const s3Url = `https://s3.${this.region}.${this.urlSuffix}/${bucketName}/${objectKey}`; + const httpUrl = `https://s3.${this.region}.${this.urlSuffix}/${bucketName}/${objectKey}`; - return { bucketName, objectKey, s3Url }; + return { bucketName, objectKey, httpUrl }; } public addDockerImageAsset(asset: DockerImageAssetSource): DockerImageAssetLocation { From a69889c0d1e173fdafab83c42fd6cf7088b61ea3 Mon Sep 17 00:00:00 2001 From: Ryan England Date: Tue, 14 Apr 2020 01:13:21 -0400 Subject: [PATCH 2/2] feat(aws-s3-asssets): add s3ObjectUrl property to asset closes #7221 Add s3ObjectUrl property. Rename s3Url to httpUrl to prevent confusion. Update integ.assets.refs.lit.ts and integ.assets.refs.lit.expected.json. Integration tests completed successfully. Shout out to Elad Ben-Israel for his guidance. --- packages/@aws-cdk/aws-s3-assets/README.md | 3 +- packages/@aws-cdk/aws-s3-assets/lib/asset.ts | 13 +++- .../test/integ.assets.refs.lit.expected.json | 60 +++++++++++++++---- .../test/integ.assets.refs.lit.ts | 3 +- 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/packages/@aws-cdk/aws-s3-assets/README.md b/packages/@aws-cdk/aws-s3-assets/README.md index 44d054c962eab..e696bebca6e6a 100644 --- a/packages/@aws-cdk/aws-s3-assets/README.md +++ b/packages/@aws-cdk/aws-s3-assets/README.md @@ -40,9 +40,10 @@ to an S3 bucket during deployment. `Asset` constructs expose the following deploy-time attributes: + * `httpUrl` - the HTTP URL of the asset (i.e. https://s3.us-east-1.amazonaws.com/mybucket/mykey.zip) * `s3BucketName` - the name of the assets S3 bucket. * `s3ObjectKey` - the S3 object key of the asset file (whether it's a file or a zip archive) - * `s3Url` - the S3 URL of the asset (i.e. https://s3.us-east-1.amazonaws.com/mybucket/mykey.zip) + * `s3UrlObject` - the S3 URL of the asset (i.e. s3://mybucket/mykey.zip) In the following example, the various asset attributes are exported as stack outputs: diff --git a/packages/@aws-cdk/aws-s3-assets/lib/asset.ts b/packages/@aws-cdk/aws-s3-assets/lib/asset.ts index d2b7712564e03..0385e335ee4f9 100644 --- a/packages/@aws-cdk/aws-s3-assets/lib/asset.ts +++ b/packages/@aws-cdk/aws-s3-assets/lib/asset.ts @@ -51,6 +51,12 @@ export interface AssetProps extends AssetOptions { * and then can be referenced within a CDK application. */ export class Asset extends cdk.Construct implements assets.IAsset { + /** + * Attribute which represents the HTTP URL of this asset. + * @example https://s3.us-west-1.amazonaws.com/bucket/key + */ + public readonly httpUrl: string; + /** * Attribute that represents the name of the bucket this asset exists in. */ @@ -63,9 +69,9 @@ export class Asset extends cdk.Construct implements assets.IAsset { /** * Attribute which represents the S3 URL of this asset. - * @example https://s3.us-west-1.amazonaws.com/bucket/key + * @example s3://bucket/key */ - public readonly s3Url: string; + public readonly s3ObjectUrl: string; /** * The path to the asset (stringinfied token). @@ -116,9 +122,10 @@ export class Asset extends cdk.Construct implements assets.IAsset { fileName: staging.stagedPath }); + this.httpUrl = location.httpUrl; this.s3BucketName = location.bucketName; this.s3ObjectKey = location.objectKey; - this.s3Url = location.s3Url; + this.s3ObjectUrl = `s3://${this.s3BucketName}/${this.s3ObjectKey}`; this.bucket = s3.Bucket.fromBucketName(this, 'AssetBucket', this.s3BucketName); diff --git a/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json index 6b25a2e5cdc63..dcd5cc5a123d3 100644 --- a/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json +++ b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json @@ -14,6 +14,54 @@ } }, "Outputs": { + "HTTPURL": { + "Value": { + "Fn::Join": [ + "", + [ + "https://s3.", + { + "Ref": "AWS::Region" + }, + ".", + { + "Ref": "AWS::URLSuffix" + }, + "/", + { + "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3Bucket50B5A10B" + }, + "/", + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3VersionKey1F7D75F9" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3VersionKey1F7D75F9" + } + ] + } + ] + } + ] + ] + } + }, "S3BucketName": { "Value": { "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3Bucket50B5A10B" @@ -54,20 +102,12 @@ ] } }, - "S3URL": { + "S3ObjectUrl": { "Value": { "Fn::Join": [ "", [ - "https://s3.", - { - "Ref": "AWS::Region" - }, - ".", - { - "Ref": "AWS::URLSuffix" - }, - "/", + "s3://", { "Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3Bucket50B5A10B" }, diff --git a/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts index b7311353f8de1..94185dc587117 100644 --- a/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts +++ b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts @@ -12,9 +12,10 @@ class TestStack extends cdk.Stack { path: path.join(__dirname, 'sample-asset-directory') }); + new cdk.CfnOutput(this, 'HTTPURL', { value: asset.httpUrl }); new cdk.CfnOutput(this, 'S3BucketName', { value: asset.s3BucketName }); new cdk.CfnOutput(this, 'S3ObjectKey', { value: asset.s3ObjectKey }); - new cdk.CfnOutput(this, 'S3URL', { value: asset.s3Url }); + new cdk.CfnOutput(this, 'S3ObjectUrl', { value: asset.s3ObjectUrl }); /// !hide // we need at least one resource