Skip to content

Commit

Permalink
Merge 790318e into ad91fd2
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaeng authored Apr 27, 2020
2 parents ad91fd2 + 790318e commit 8cc9abe
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-s3-assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,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:

Expand Down
13 changes: 10 additions & 3 deletions packages/@aws-cdk/aws-s3-assets/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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).
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -54,20 +102,12 @@
]
}
},
"S3URL": {
"S3ObjectUrl": {
"Value": {
"Fn::Join": [
"",
[
"https://s3.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
"s3://",
{
"Ref": "AssetParameters6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2S3Bucket50B5A10B"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8cc9abe

Please sign in to comment.