Skip to content

feat: migrate aws-sdk v2 to @aws-sdk/client-ec2 v3 (Phase 1)#17

Merged
kurok merged 2 commits intofeat/al2023-supportfrom
feat/7-aws-sdk-v3
Apr 21, 2026
Merged

feat: migrate aws-sdk v2 to @aws-sdk/client-ec2 v3 (Phase 1)#17
kurok merged 2 commits intofeat/al2023-supportfrom
feat/7-aws-sdk-v3

Conversation

@kurok
Copy link
Copy Markdown

@kurok kurok commented Apr 21, 2026

Closes #7. Part of plan #15.

Scope

  • Drop aws-sdk v2 (end-of-support Nov 2025, source of the DEP0169 url.parse() warning fix: silence DEP0169 url.parse deprecation from bundled aws-sdk v2 #6 papered over).
  • Add @aws-sdk/client-ec2@3.1033.0 (per-service package — dramatically smaller than the monolith).
  • Rewrite src/aws.js on the EC2Client + Command pattern.
  • Bump @vercel/ncc 0.25.1 → 0.38.4 (webpack-5, parses modern JS transitive deps that the old ncc choked on).
  • Broaden the verify-dist CI check to diff the whole dist/ tree — ncc 0.38 code-splits into chunks alongside index.js.
  • Drop the now-unneeded NODE_OPTIONS=--openssl-legacy-provider from the build step.

External-contract compatibility

Every with: input consumers pass stays the same (mode, github-token, ec2-image-*, ec2-instance-type, subnet-id, security-group-id, eip-allocation-id, iam-role-name, aws-resource-tags), as do the two outputs (label, ec2-instance-id). The only consumer action post-merge is rotating their SHA pin — same as machulav#158 / machulav#164 / machulav#165.

API mapping

v2 v3
new AWS.EC2() new EC2Client({})
ec2.describeImages(p).promise() client.send(new DescribeImagesCommand(p))
ec2.runInstances(p).promise() client.send(new RunInstancesCommand(p))
ec2.terminateInstances(p).promise() client.send(new TerminateInstancesCommand(p))
ec2.associateAddress(p).promise() client.send(new AssociateAddressCommand(p))
ec2.waitFor('instanceRunning', p).promise() waitUntilInstanceRunning({client, maxWaitTime: 300}, p)

Bundle

v2 bundle v3 bundle
dist/index.js ~7.9 MB 3.4 MB
chunks (none) +10 files, ~3.3 MB combined
total 7.9 MB 6.7 MB

Net smaller.

Verification

Dogfood plan (per #15 tracker)

After merge: rotate the SHA pin in terraform-provider-namecheap/.github/workflows/ci.yml to the new feat/al2023-support tip, confirm the acceptance-test pipeline starts an EC2 runner, registers it, runs make testacc, and terminates cleanly. That's the end-to-end regression test that matters for this refactor.

Note on the DEP0169 filter

The process.emitWarning override from #6 stays in place. v3 uses WHATWG URL and doesn't emit DEP0169, so the filter is inert on the current tip. Removing it is a cleanup that I'd rather keep out of this PR's scope — smaller diff = easier rollback if something unexpected turns up in dogfood.

kurok added 2 commits April 21, 2026 08:32
Completes Phase 1 (issue #7) of the modernization plan.

## Dependency changes

- Remove 'aws-sdk' ^2.809.0 (in maintenance mode since late 2024;
  end-of-support announced for Nov 2025; emits DEP0169 on url.parse()
  in modern Node).
- Add '@aws-sdk/client-ec2' 3.1033.0 pinned exact. Per-service package
  is dramatically smaller than v2's monolithic bundle.
- Bump '@vercel/ncc' 0.25.1 -> 0.38.4. The old ncc couldn't parse
  modern JS (private class fields in v3's transitive deps); 0.38 is
  webpack-5-based and handles current syntax.

## Code changes (src/aws.js)

Rewrite on the EC2Client + Command pattern:

- EC2Client({}) replaces 'new AWS.EC2()'. Reads region + creds from
  env (same behavior, same source — configure-aws-credentials or
  instance profile).
- client.send(new DescribeImagesCommand(params)) replaces
  ec2.describeImages(params).promise().
- client.send(new RunInstancesCommand(params)) replaces
  ec2.runInstances(params).promise().
- client.send(new TerminateInstancesCommand(params)) replaces
  ec2.terminateInstances(params).promise().
- client.send(new AssociateAddressCommand(params)) replaces
  ec2.associateAddress(params).promise().
- waitUntilInstanceRunning({client, maxWaitTime: 300}, {InstanceIds})
  replaces ec2.waitFor('instanceRunning', ...).promise().

External action contract (inputs + outputs) is unchanged. Consumer
workflows (notably terraform-provider-namecheap) do not need any
change beyond rotating their SHA pin.

## Bundle + CI

- 'npm run package' no longer needs NODE_OPTIONS=--openssl-legacy-provider
  (ncc 0.38 + webpack 5 don't use the legacy module-hash MD4 path).
- dist/ now contains code-split chunk files (136.index.js, 360.index.js,
  etc.) alongside dist/index.js. All must be committed; the verify-dist
  CI check in pr.yml is broadened to diff the whole dist/ tree.
- Bundle size: 7.9 MB -> 3.4 MB main (+ ~3.3 MB in chunks). Net smaller
  than v2.

## Backward compatibility

The DEP0169 process.emitWarning filter added in #6 stays in place.
The v3 bundle doesn't emit DEP0169, so the filter is effectively inert
on the current tip — cleanup is a follow-up, not part of this PR's scope.

## Verification

- npm test: 21 tests pass across tests/utils.test.js + tests/config.test.js
  (no aws.js tests yet; those land as Phase 8.b after Phase 4/5 stop
  rewriting aws.js).
- npm run lint: clean.
- Bundle builds cleanly on Node 20 without OpenSSL legacy provider.

Signed-off-by: yuriyryabikov <22548029+kurok@users.noreply.github.com>
ncc 0.38's output contains 451 source-embedded CR bytes inside string
literals (aws-sdk transitive deps). When dist/ is committed through
git's default line-ending normalization, those CRs are stripped into
the blob, but every subsequent 'npm run package' reproduces them —
creating a permanent, symmetric 451/451 diff that the verify-dist CI
gate correctly flagged as drift.

Mark the whole dist/ tree as binary via .gitattributes so git never
converts line endings in that path. What ncc writes is what git
stores; CI's rebuild produces byte-identical output.

Signed-off-by: yuriyryabikov <22548029+kurok@users.noreply.github.com>
@kurok kurok merged commit a1bd2f9 into feat/al2023-support Apr 21, 2026
4 checks passed
@kurok kurok deleted the feat/7-aws-sdk-v3 branch April 21, 2026 07:51
kurok added a commit to namecheap/terraform-provider-namecheap that referenced this pull request Apr 21, 2026
…181)

namecheap/ec2-github-runner#17 merged. The new feat/al2023-support
tip picks up the aws-sdk v2 to @aws-sdk/client-ec2 v3 migration and
the ncc 0.25 to 0.38 bump.

This rotation is the dogfood verification called out in the #15
tracker: confirms the provider's acceptance test pipeline still
lifts an EC2 runner, registers it, runs make testacc, and
terminates cleanly against the v3-based action code.

Rotation chain: 54459d6 -> a1bd2f9 (Phase 1).

Signed-off-by: yuriyryabikov <22548029+kurok@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant