winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.05k stars 196 forks source link

`aws.Region.of(this)` API #6794

Open Chriscbr opened 4 months ago

Chriscbr commented 4 months ago

Use Case

As a user, when I'm compiling a Wing app to one of the AWS platforms, I'd like to have a way to easily access the AWS region my app's resources are being deployed to so that I can use it for constructing ARNs and other things like that.

We already use region information in the TypeScript implementations of some of the built-in cloud classes: https://github.com/winglang/wing/blob/734a760cc94748deb880b424e92b0fac4a696411/libs/wingsdk/src/target-tf-aws/api.ts#L319-L322

Proposed Solution

bring aws;

let region = aws.region; // str

Implementation Notes

By default the AWS Terraform Provider operates in a single region and also CloudFormation runs deployments in a single region.

The implementation of aws.region needs to somehow depend on which target you're compiling to (tf-aws or awscdk).

Component

SDK

Community Notes

eladb commented 4 months ago

The "correct" way to obtain the current region and account is using a terraform data element.

See https://github.com/winglang/winglibs/blob/main/containers/aws.w as an example.

I suspect a global aws.region won't work without tree scope, so it will need to be something like: aws.Region.of(this) or aws.Environment.of(this).region

Chriscbr commented 4 months ago

Mmm - I see, yeah that makes sense.

eladb commented 1 week ago

We need this!