Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets #371

Merged
merged 9 commits into from
Jul 18, 2018
Merged

Assets #371

merged 9 commits into from
Jul 18, 2018

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Jul 18, 2018

Assets represent local files or directories which can be bundled as part
of CDK constructs. During deployment, the toolkit will upload assets
to the "Toolkit Bucket", and use CloudFormation Parameters to reference
the asset in deploy-time.

Assets expose the following deploy-time attributes:

  • s3BucketName
  • s3ObjectKey
  • s3Url

Furthermore, the asset.grantRead(principal) will add IAM read permissions
for the asset to the desired principal.

See @aws-cdk/assets/README for more details and examples

Note that the actual mechanism to emit and deploy assets will likely change as we progress towards the app model (#233). This is also related to #85.

Assets represent local files or directories which can be bundled as part
of CDK constructs. During deployment, the toolkit will upload assets
to the "Toolkit Bucket", and use CloudFormation Parameters to reference
the asset in deploy-time.

Assets expose the following deploy-time attributes:

 * s3BucketName
 * s3ObjectKey
 * s3Url

Furthermore, the `asset.grantRead(principal)` will add IAM read permissions
for the asset to the desired principal.
@@ -0,0 +1,187 @@
import cdk = require('@aws-cdk/core');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not using import * as cdk from '@aws-cdk/core'; and similar for our own libraries, but using it for node libraries? I find this confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should standardize around import x = require('y') for star imports across the board. It's a clean and concise syntax.

* Path refers to a directory on disk, the contents of the directory is
* archived into a .zip.
*/
ZipDirectory = 'zip',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the string value here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there may be an interest for uploading a given directory (un-zipp'd). It can be painful to have to map every file individually when there are a lot...

Would expect the URL in this case to be that of where the files were uploaded - with the same structure (so I can just append path elements to get a particular file).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always add additional packaging schemes, such as Directory for example, in which case the URL will point to the prefix. We will add as needed.

throw new Error(`Cannot find asset at ${props.path}`);
}

if (props.packaging === AssetPackaging.ZipDirectory) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch anyone?

"Fn::Join": [
"",
[
"arn",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Why would you runtime-join up to 7 string literals, including empty strings, instead of pre-joining them at code-authoring time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export const ASSET_METADATA = 'aws:cdk:asset';
export interface AssetMetadataEntry {
path: string;
packaging: 'zip' | 'file';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overly restrictive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to change the cxapi every time we add a new supported type. It feels unnecessary granted this could be String. Otherwise, why is it not an enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it makes sense that we'll have to invalidate cxapi if we add more supported types because the change needs to be supported by the toolkit, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I guess.


const s3url = `s3://${toolkitInfo.bucketName}/${key}`;
if (changed) {
success(` 👜 Asset ${asset.path} (directory zip) uploaded to ${s3url}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A handbag? 📦?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, an asset!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 👑 is an asset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

if (changed) {
success(` 👜 Asset ${asset.path} (directory zip) uploaded to ${s3url}`);
} else {
success(` 👜 Asset ${asset.path} (directory zip) already exists in ${s3url}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already exists

I may perceive this as an error/warning that the file wasn't uploaded because there's already a file there in S3; when what you mean to say is what's in S3 is equal to what you meant to upload.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Any recommended wording?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/already exists/is already up-to-date/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const s3url = `s3://${toolkitInfo.bucketName}/${key}`;
if (changed) {
success(` 👜 Asset ${asset.path} uploaded to ${s3url}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the "distinctive" messaging here is worth that amount of duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be useful for people to know that an asset was changed, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm referring to the two nearly identical code paths that differ mostly on what they pass to success. The code for zip versus file versions aren't that different... Feels needlessly duplicative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@@ -15,7 +15,9 @@
"test": "cdk-test"
},
"cdk-build": {
"pre": ["./generate.sh"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge mishap. Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's just reformatting and sorting the JSON...

"mockery": "^2.1.0",
"pkglint": "^0.7.3-beta",
"cdk-build-tools": "^0.7.3-beta"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those should also not be deleted...

Elad Ben-Israel added 5 commits July 18, 2018 16:13
The `bucketUrl` returns the URL of the bucket
and `urlForObject(key)` returns the URL of an
object within the bucket.

Furthermore: `iam.IIdentityResource` was soft-renamed
to `iam.IPrincipal` (IIdentityResource is 
still supported).
@eladb eladb merged commit ac1d907 into benisrae/s3-urls Jul 18, 2018
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants