Skip to content

Commit

Permalink
fix: pinpoint feature flag read (#8496)
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Hajdrik committed Oct 21, 2021
1 parent 744c537 commit f078323
Showing 1 changed file with 25 additions and 24 deletions.
Expand Up @@ -3,31 +3,8 @@ const { FeatureFlags } = require('amplify-cli-core');
const proxyAgent = require('proxy-agent');
const configurationManager = require('../configuration-manager');
const { formUserAgentParam } = require('./user-agent');
const latestPinpointRegions = FeatureFlags.getNumber('latestRegionSupport.pinpoint');

const defaultPinpointRegion = 'us-east-1';
const serviceRegionMap = {
'us-east-1': 'us-east-1',
'us-east-2': 'us-east-1',
'sa-east-1': 'us-east-1',
'ca-central-1': latestPinpointRegions >= 1 ? 'ca-central-1' : 'us-east-1',
'us-west-1': 'us-west-2',
'us-west-2': 'us-west-2',
'cn-north-1': 'us-west-2',
'cn-northwest-1': 'us-west-2',
'ap-south-1': latestPinpointRegions >= 1 ? 'ap-south-1' : 'us-west-2',
'ap-northeast-3': 'us-west-2',
'ap-northeast-2': latestPinpointRegions >= 1 ? 'ap-northeast-2' : 'us-west-2',
'ap-southeast-1': latestPinpointRegions >= 1 ? 'ap-southeast-1' : 'us-west-2',
'ap-southeast-2': latestPinpointRegions >= 1 ? 'ap-southeast-2' : 'us-west-2',
'ap-northeast-1': latestPinpointRegions >= 1 ? 'ap-northeast-1' : 'us-west-2',
'eu-central-1': 'eu-central-1',
'eu-north-1': 'eu-central-1',
'eu-west-1': 'eu-west-1',
'eu-west-2': latestPinpointRegions >= 1 ? 'eu-west-2' : 'eu-west-1',
'eu-west-3': 'eu-west-1',
'me-south-1': 'ap-south-1',
};

async function getConfiguredPinpointClient(context, category, action, envName) {
let cred = {};
Expand Down Expand Up @@ -62,14 +39,38 @@ async function getConfiguredPinpointClient(context, category, action, envName) {
}

function mapServiceRegion(region) {
const serviceRegionMap = getPinpointRegionMapping();
if (serviceRegionMap[region]) {
return serviceRegionMap[region];
}
return defaultPinpointRegion;
}

function getPinpointRegionMapping() {
return serviceRegionMap;
const latestPinpointRegions = FeatureFlags.getNumber('latestRegionSupport.pinpoint');

return {
'us-east-1': 'us-east-1',
'us-east-2': 'us-east-1',
'sa-east-1': 'us-east-1',
'ca-central-1': latestPinpointRegions >= 1 ? 'ca-central-1' : 'us-east-1',
'us-west-1': 'us-west-2',
'us-west-2': 'us-west-2',
'cn-north-1': 'us-west-2',
'cn-northwest-1': 'us-west-2',
'ap-south-1': latestPinpointRegions >= 1 ? 'ap-south-1' : 'us-west-2',
'ap-northeast-3': 'us-west-2',
'ap-northeast-2': latestPinpointRegions >= 1 ? 'ap-northeast-2' : 'us-west-2',
'ap-southeast-1': latestPinpointRegions >= 1 ? 'ap-southeast-1' : 'us-west-2',
'ap-southeast-2': latestPinpointRegions >= 1 ? 'ap-southeast-2' : 'us-west-2',
'ap-northeast-1': latestPinpointRegions >= 1 ? 'ap-northeast-1' : 'us-west-2',
'eu-central-1': 'eu-central-1',
'eu-north-1': 'eu-central-1',
'eu-west-1': 'eu-west-1',
'eu-west-2': latestPinpointRegions >= 1 ? 'eu-west-2' : 'eu-west-1',
'eu-west-3': 'eu-west-1',
'me-south-1': 'ap-south-1',
};
}

module.exports = {
Expand Down

0 comments on commit f078323

Please sign in to comment.