[2/6] Migrate AWS read paths and state discovery to SDK v3#194
Draft
GrahamCampbell wants to merge 1 commit intov3-1from
Draft
[2/6] Migrate AWS read paths and state discovery to SDK v3#194GrahamCampbell wants to merge 1 commit intov3-1from
GrahamCampbell wants to merge 1 commit intov3-1from
Conversation
d2651f1 to
74b7641
Compare
There was a problem hiding this comment.
Pull request overview
This PR continues the AWS SDK v3 migration by switching several “read” code paths (CloudFormation export resolution, stack info/resource counting, metrics/logs reads, deployment listing and change detection) from the legacy provider.request interface to direct SDK v3 clients, while adding shared v3 error-shape utilities and new test infrastructure for stubbing v3 clients/paginators.
Changes:
- Add
aws-sdk-v3-errorutilities and update callers to use them for consistent error/region handling. - Migrate multiple AWS “read” paths to SDK v3 clients/commands (CloudFormation, S3, Lambda, CloudWatch, CloudWatch Logs, API Gateway).
- Add/extend unit tests plus a new
configure-aws-sdk-v3-stubandrun-serverlesssupport for SDK v3 module stubbing.
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/unit/test-lib/configure-aws-sdk-v3-stub.test.js | Adds unit coverage for the new v3 stub helper (commands, pagination, error cases). |
| test/unit/lib/plugins/aws/utils/resolve-cf-import-value.test.js | Updates tests to stub CloudFormationClient#send and validates pagination behavior. |
| test/unit/lib/plugins/aws/utils/aws-sdk-v3-error.test.js | Adds unit coverage for v3/legacy AWS error-shape normalization helpers. |
| test/unit/lib/plugins/aws/remove/index.test.js | Adds coverage for skipping S3 cleanup when CF deployment bucket resource is missing via v3-shaped errors. |
| test/unit/lib/plugins/aws/provider.test.js | Updates provider tests for v3 config/credentials behavior and v3-based CF/STS calls. |
| test/unit/lib/plugins/aws/metrics.test.js | Updates metrics tests to stub CloudWatchClient#send and validates request concurrency limiting. |
| test/unit/lib/plugins/aws/logs.test.js | Updates logs tests to stub CloudWatchLogsClient#send and validate v3 command inputs. |
| test/unit/lib/plugins/aws/lib/check-if-ecr-repository-exists.test.js | Adds unit coverage for new v3 ECR existence checks and error handling. |
| test/unit/lib/plugins/aws/lib/check-if-bucket-exists.test.js | Adds unit coverage for new v3 S3 HeadBucket checks and stable forbidden/not-found mapping. |
| test/unit/lib/plugins/aws/invoke-local/index.test.js | Updates ImportValue resolution path to stub v3 CloudFormation exports listing. |
| test/unit/lib/plugins/aws/info/get-stack-info.test.js | Updates stack info tests to stub v3 CloudFormation + ApiGatewayV2 calls. |
| test/unit/lib/plugins/aws/info/get-resource-count.test.js | Updates resource count tests to stub v3 CloudFormation and validate pagination accumulation. |
| test/unit/lib/plugins/aws/info/get-api-key-values.test.js | Updates API key value tests to use v3 CF + API Gateway clients and adds concurrency limiting coverage. |
| test/unit/lib/plugins/aws/deploy/lib/validate-template.test.js | Updates validate-template tests to stub v3 CloudFormation validateTemplate. |
| test/unit/lib/plugins/aws/deploy/lib/check-for-changes.test.js | Updates many “check for changes” tests for v3 clients, paginators, and concurrency limiting behavior. |
| test/unit/lib/plugins/aws/deploy/index.test.js | Adds coverage for deployment bucket region redirect error handling via v3 error headers. |
| test/unit/lib/plugins/aws/deploy-list.test.js | Updates deploy-list tests to v3 S3 pagination + Lambda calls and adds pagination/concurrency scenarios. |
| test/lib/run-serverless.js | Extends test harness to support SDK v3 module stubs (and exposes awsSdkV3Stub in results). |
| test/lib/configure-aws-sdk-v3-stub.js | Introduces a module-level v3 client/command/paginator stubbing facility for tests. |
| package.json | Adds missing AWS SDK v3 client packages used by the migrated code paths. |
| lib/plugins/aws/utils/resolve-cf-import-value.js | Migrates export resolution to SDK v3 CloudFormation client + ListExportsCommand. |
| lib/plugins/aws/utils/aws-sdk-v3-error.js | Adds shared helpers to read v3/legacy error codes/status/headers and classify common AWS errors. |
| lib/plugins/aws/remove/lib/bucket.js | Switches CF validation error detection to shared v3 error helpers. |
| lib/plugins/aws/provider.js | Wraps v3 credentials provider errors, migrates CF deployment bucket lookup + STS caller identity to v3. |
| lib/plugins/aws/metrics.js | Migrates CloudWatch metrics reads to SDK v3 with a concurrency limiter. |
| lib/plugins/aws/logs.js | Migrates CloudWatch Logs reads to SDK v3 and hardens empty-response handling. |
| lib/plugins/aws/lib/check-if-ecr-repository-exists.js | Migrates ECR repository existence check to SDK v3 + shared error classification. |
| lib/plugins/aws/lib/check-if-bucket-exists.js | Migrates S3 bucket existence check to SDK v3 + stable forbidden mapping. |
| lib/plugins/aws/info/get-stack-info.js | Migrates stack info reads (CF + ApiGatewayV2) to SDK v3 clients/commands. |
| lib/plugins/aws/info/get-resource-count.js | Migrates CF resource listing to SDK v3 and retains pagination via recursion. |
| lib/plugins/aws/info/get-api-key-values.js | Migrates CF stack resources + API Gateway key fetches to SDK v3 with concurrency limiting. |
| lib/plugins/aws/deploy/lib/validate-template.js | Migrates CF validateTemplate to SDK v3. |
| lib/plugins/aws/deploy/lib/ensure-valid-bucket-exists.js | Migrates custom bucket HeadBucket validation to SDK v3 and uses shared region extraction helpers. |
| lib/plugins/aws/deploy/lib/check-for-changes.js | Migrates S3/Lambda/CloudWatchLogs/CloudFormation “read” requests to SDK v3 with pagination + concurrency limiting. |
| lib/plugins/aws/deploy-list.js | Migrates deploy list S3 listing (with pagination) and Lambda reads to SDK v3 with concurrency limiting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
+12
| const result = await cloudFormation.send(new ListExportsCommand(sdkParams)); | ||
| const targetExportMeta = result.Exports.find((exportMeta) => exportMeta.Name === name); | ||
| if (targetExportMeta) return targetExportMeta.Value; | ||
| if (result.NextToken) { | ||
| return resolveCfImportValue(provider, name, { NextToken: result.NextToken }); |
Comment on lines
+14
to
20
| const cloudFormation = new CloudFormationClient(await this.provider.getAwsSdkV3Config()); | ||
| const result = await cloudFormation.send(new ListStackResourcesCommand(params)); | ||
| if (Object.keys(result).length) { | ||
| this.gatheredData.info.resourceCount = resourceCount + result.StackResourceSummaries.length; | ||
| if (result.NextToken) { | ||
| return this.getResourceCount(result.NextToken, this.gatheredData.info.resourceCount); | ||
| } |
Comment on lines
372
to
388
| @@ -382,6 +383,8 @@ describe('AwsInvokeLocal', () => { | |||
| expect(result).to.deep.equal({ | |||
| IMPORTED: 'imported-value', | |||
| }); | |||
| expect(listExportsStub).to.have.been.calledOnce; | |||
| CloudFormationClient.prototype.send.restore(); | |||
| }); | |||
Comment on lines
+17
to
+30
| async function releasePendingRequestsUntilSettled(pendingResolvers, promise) { | ||
| let isSettled = false; | ||
| promise | ||
| .finally(() => { | ||
| isSettled = true; | ||
| }) | ||
| .catch(() => {}); | ||
| while (!isSettled) { | ||
| await Promise.resolve(); | ||
| for (const resolve of pendingResolvers.splice(0)) resolve(); | ||
| await Promise.resolve(); | ||
| } | ||
| return promise; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.