Add a requireRegion helper function
This change adds a requireRegion helper function to the AWS library,
enabling easy fetching of the current region (and/or throwing if the
region hasn't been properly configured).
@@ -6,6 +6,14 @@ import {Region} from "../types";
// to minimize the possibility of accidental deployment differences due to a changing environment variable.
export let region: Region | undefined;
+// requireRegion fetches the AWS region, requiring that it exists; if it has not been configured, an error is thrown.
+export function requireRegion(): Region {
+ if (region === undefined) {
+ throw new Error("No AWS region has been configured");
+ }
+ return region;
+}
+
// accessKeyId configures the access key ID used to access AWS. This is a secret. If not provided, the
// provider will look in the standard places (~/.aws/credentials, AWS_ACCESS_KEY_ID, etc).
export let accessKeyId: string | undefined;
