-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(lambda-layer-awscli): Dynamically load asset for AwsCliLayer, with bundled fallback #21938
feat(lambda-layer-awscli): Dynamically load asset for AwsCliLayer, with bundled fallback #21938
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Pull Request Linter fails with the following errors:
❌ Features must contain a change to a README file.
❌ Features must contain a change to an integration test file and the resulting snapshot.
PRs must pass status checks before we can provide a meaningful review.
Pull Request updated. Dissmissing previous PRLinter Review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Pull Request Linter fails with the following errors:
❌ Features must contain a change to a README file.
❌ Features must contain a change to an integration test file and the resulting snapshot.
❌ CLI code has changed. A maintainer must run the code through the testing pipeline (git fetch origin pull/21938/head && git push -f origin FETCH_HEAD:test-main-pipeline), then add the 'pr-linter/cli-integ-tested' label when the pipeline succeeds.
PRs must pass status checks before we can provide a meaningful review.
This change is exempt integ test changes because one hard requirement is that it does not change the behavior or content of existing stacks. |
Pull Request updated. Dissmissing previous PRLinter Review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Pull Request Linter fails with the following errors:
❌ Features must contain a change to a README file.
❌ CLI code has changed. A maintainer must run the code through the testing pipeline (git fetch origin pull/21938/head && git push -f origin FETCH_HEAD:test-main-pipeline), then add the 'pr-linter/cli-integ-tested' label when the pipeline succeeds.
PRs must pass status checks before we can provide a meaningful review.
Pull Request updated. Dissmissing previous PRLinter Review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Pull Request Linter fails with the following errors:
❌ Features must contain a change to a README file.
❌ CLI code has changed. A maintainer must run the code through the testing pipeline (git fetch origin pull/21938/head && git push -f origin FETCH_HEAD:test-main-pipeline), then add the 'pr-linter/cli-integ-tested' label when the pipeline succeeds.
PRs must pass status checks before we can provide a meaningful review.
packages/@aws-cdk/lambda-layer-awscli/layer/download-fallback.sh
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/lambda-layer-awscli/layer/download-fallback.sh
Outdated
Show resolved
Hide resolved
if (assetPackage) { | ||
// ask for feedback here | ||
const asset = new assetPackage.AwsCliAsset(scope, `${id}-asset`); | ||
code = lambda.Code.fromBucket(asset.bucket, asset.s3ObjectKey); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It all happens at runtime in JavaScript, which doesn't have types. So: we can check for the presence of the symbol, but never its type.
if (!(assetPackage as any).AwsCliAsset) {
throw new Error('Ruh roh');
}
This is probably good enough, though we might need to stick an API version somewhere...
} | ||
availableVersion = AwsCliLayer.requireWrapper(path.join(assetPackagePath, '../../package.json'), logs).version; | ||
|
||
if (targetVersion === availableVersion) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we care exactly? Do we need semver
in here to check range compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to log if the version is there but we rejected it btw. That's good info to know.
"bundledDependencies": [ | ||
"semver" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I did this correctly... Adding the non-JSII package as a dependency forced me to add it here as well. And then having a bundled dependency led me to add it to the "nohoist" list in our top-level package.json
using yarn build --fix
. It's strange because semver
is already a dependency of aws-cdk-lib
, so this will get ignored in the release anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially, we could add a utility function in @aws-cdk/core
that does the version range check and uses the semver
bundled there. Just available to TS/JS, nothing else would be good enough to start. Something like:
export function versionMatchesRange(version: string, range: string) {
// Use semver here
}
…erated by the build
The pull request linter fails with the following errors:
PRs must pass status checks before we can provide a meaningful review. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
cp $dir/lib/layer.zip ./lib | ||
|
||
target_version=$(node -pe 'require("@aws-cdk/asset-awscli-v1/package.json").version') | ||
echo "export const TARGET_VERSION = '${target_version}';" > lib/asset-package-version.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "export const TARGET_VERSION = '${target_version}';" > lib/asset-package-version.ts | |
echo "export const RECOMMENDED_VERSION = '${target_version}';" > lib/asset-package-version.ts |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modulo tiny things I think this looks good!
} | ||
|
||
if (fallback) { | ||
Annotations.of(this).addWarning(`[ACTION REQUIRED] Your CDK application is using ${this.constructor.name}. Add a dependency on ${AwsCliLayer.assetPackageName}, or the equivalent in your language, to remove this warning. See https://github.com/aws/aws-cdk/issues/22470 for more information.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations.of(this).addWarning(`[ACTION REQUIRED] Your CDK application is using ${this.constructor.name}. Add a dependency on ${AwsCliLayer.assetPackageName}, or the equivalent in your language, to remove this warning. See https://github.com/aws/aws-cdk/issues/22470 for more information.`); | |
Annotations.of(this).addWarning(`[ACTION REQUIRED] Your CDK application is using ${this.constructor.name} and synthesizes in an environment where ${AwsCliLayer.assetPackageName} cannot be automatically downloaded. Add a dependency on ${AwsCliLayer.assetPackageName}, or the equivalent in your language to remove this warning. See https://github.com/aws/aws-cdk/issues/22470 for more information.`); |
@madeline-k / @kaizencc should this be closed? |
Closing for now. @madeline-k had thoughts to poc a different solution, but can revive it later. |
This PR introduces a change to dynamically load the large Asset zip file used by the AwsCliLayer construct from a separate package: https://www.npmjs.com/package/@aws-cdk/asset-awscli-v1/. This change is part of aws/aws-cdk-rfcs#430
This may not work in some customer's environments, so we will release this feature in two steps.
@aws-cdk/asset-awscli-v1
package into aws-cdk-lib to use as a fallback for customers whose build environments are not able to install from npm. For customers who will experience a breaking change when that fallback is removed, warnings and CLI notices will be printed for them linking to instructions to update and prepare for the version without the fallback. The first phase will not significantly affect the size of the aws-cdk-lib package.Remaining:
When this is released, we will also create a CLI Notice. The PR for that notice is open here: cdklabs/aws-cdk-notices#21
The github issue will be here: #22470
All Submissions:
Adding new Unconventional Dependencies:
New Features
yarn integ
to deploy the infrastructure and generate the snapshot (i.e.yarn integ
without--dry-run
)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license