Skip to content

Commit

Permalink
feat: allow to specify region for data-module (#4)
Browse files Browse the repository at this point in the history
* allow to specify region for data-module

Co-authored-by: Norbert Nader <nnader@amazon.com>
  • Loading branch information
NorbertNader and NorbertNader authored Nov 18, 2021
1 parent 113a1bd commit ae2ef66
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const STRING_ASSET_ID = '9a9ca8e2-779d-443f-93a9-c287fd8f9c66';
const STRING_PROPERTY_ID = '9530e220-b353-4331-b4b3-cf0949c8684d';

const DEMO_TURBINE_ASSET_1 = 'c9884a1e-bbc1-4692-a107-327c4b76cea7';
const DEMO_TURBINE_ASSET_1 = '4df123fc-dc29-470e-8fd2-9242a2d3fa17';

const DEMO_TURBINE_ASSET_1_PROPERTY_1 = 'a051b46f-b9ed-431f-8d1b-470660980c53';
const DEMO_TURBINE_ASSET_1_PROPERTY_2 = 'd0ac14ae-975e-4cea-9418-3ad6c9ce5559';
const DEMO_TURBINE_ASSET_1_PROPERTY_3 = '0dade017-e20d-4d79-9319-1e73d36c7987';
const DEMO_TURBINE_ASSET_1_PROPERTY_4 = 'ba6588b4-b580-429c-ac60-26ea3bd8b939';
const DEMO_TURBINE_ASSET_1_PROPERTY_1 = '59868144-6bb2-4a96-9413-aa58d9398a07';
const DEMO_TURBINE_ASSET_1_PROPERTY_2 = '089948a3-71e5-4fbe-bd13-18f12a076ca7';
const DEMO_TURBINE_ASSET_1_PROPERTY_3 = '04f5dcbd-f5b1-4f41-a526-84203d3af3aa';
const DEMO_TURBINE_ASSET_1_PROPERTY_4 = 'e7a6fce5-4486-4a23-b40b-8a68cb493f02';

export const STRING_QUERY = {
source: 'site-wise',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const VIEWPORT = { duration: 3 * 1000 * 60 };
})
export class TestingGround {
componentWillLoad() {
initialize({ awsCredentials: getEnvCredentials() });
initialize({ awsCredentials: getEnvCredentials(), awsRegion: 'us-east-1' });
}

render() {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/data-module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ let dataModule: DataModule | undefined = undefined;
*/
export const initialize = ({
awsCredentials,
awsRegion,
registerDataSources = true,
}: {
awsCredentials?: Credentials | Provider<Credentials>;
awsRegion?: string;
registerDataSources?: boolean;
}) => {
dataModule = new IotAppKitDataModule();
if (registerDataSources && awsCredentials != null) {
/** Automatically registered data sources */
dataModule.registerDataSource(createDataSource(sitewiseSdk(awsCredentials)));
dataModule.registerDataSource(createDataSource(sitewiseSdk(awsCredentials, awsRegion)));
} else if (registerDataSources && awsCredentials == null) {
console.warn(
'site-wise data-source failed to register. Must provide field `awsCredentials` for the site-wise data-source to register.'
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/data-sources/site-wise/sitewise-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { IoTSiteWiseClient } from '@aws-sdk/client-iotsitewise';
import { Credentials, Provider } from '@aws-sdk/types';

// Fall back region if none provided as an env variable `AWS_REGION`.
const DEFAULT_REGION = 'us-west-2';

export const sitewiseSdk = (credentials: Credentials | Provider<Credentials>) =>
export const sitewiseSdk = (credentials: Credentials | Provider<Credentials>, awsRegion?: string) =>
new IoTSiteWiseClient({
region: DEFAULT_REGION,
endpoint: `https://iotsitewise.${DEFAULT_REGION}.amazonaws.com/`,
region: awsRegion || DEFAULT_REGION,
endpoint: `https://iotsitewise.${awsRegion || DEFAULT_REGION}.amazonaws.com/`,
credentials,
});

0 comments on commit ae2ef66

Please sign in to comment.