function-upload-to-bucket/pulumi/main.ts: `aws:region` config value is never used

Open Beginner friendly
#7,301 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
aws, typescript
Domain
documentation

Research direction

Start at docs/docs/src/examples/function-upload-to-bucket/pulumi/main.ts, line 8, where config.require("aws:region") is read into region and never used. Confirm the config object has no other use, then either delete the two lines or read the region from the aws namespace if the example should show it. Done when the sample has no unused config read and still deploys with aws:region set in the stack.

Written by the indexing model from the issue text.

Description

✨ enhancement needs-discussion
I tried this:

We read the Pulumi version of the function-upload-to-bucket docs example. Line 8 of main.ts reads the config value aws:region into region, but region is never used. The line has no effect on what is deployed, and because the key is looked up in the project namespace, pulumi up can stop with a missing-config error even when aws:region is set. This comes from reading the source; we did not deploy the example.

File: docs/docs/src/examples/function-upload-to-bucket/pulumi/main.ts (line 8)

Finding: Unused config value

const region = config.require("aws:region");
This happened:

What we found: region is not used anywhere else in the file: no resource, output or interpolation refers to it, and the config object is used only on this line. The AWS provider already takes its region from the aws:region stack config, so this line has no effect on what is deployed. Also, new pulumi.Config() scopes keys to the project, so this call looks up s3-lambda-pulumi:aws:region rather than aws:region.

Why it matters: Readers comparing tools on the docs page see an extra required config read that does nothing, which makes the Pulumi sample longer and suggests that the region must be wired by hand. Because the key is project-scoped, pulumi up can fail with a missing-config error even when aws:region is set.

I expected this:

The Pulumi sample reads only config values that it uses, and leaves the region to the AWS provider's own aws:region setting.

Suggested fix: Remove the two unused lines (the config object is used only here):

-const config = new pulumi.Config();
-const region = config.require("aws:region");

The AWS provider still reads aws:region from the stack config. If the sample should show the region explicitly, read it from the aws namespace instead, e.g. const region = aws.config.region; or new pulumi.Config("aws").require("region"), and then use it. This is not a breaking change.

Anything else?

We are researchers studying the quality of infrastructure-as-code templates, and this report refers to commit b65ae5c. The findings come from a static analyzer, the text was drafted with the help of an AI assistant, and we checked both by hand.

If this is intentional, please let us know or simply close the issue. If it helps, we are happy to open a pull request with the fix. Thank you!

Dominant language
TypeScript
Stars
5.4k
Forks
217
Avg merge
3h 45m
Merged PRs (30d)
1

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from winglang/wing

All issues in winglang/wing

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.