0

I have a dev and prod cognito pool, a dev/prod lambda function that pushes to a dev/prod dynamoDb table.

Is there a simple way to have it know when to use the prod credentials (pool id, etc), and when to use the dev credentials?

And same to do with firing the appropriate dev/prod API gateway apis that check the appropriate pools for authentication, and post to the appropriate dynamoDb tables? For now I just manually change the tokens, and in API Gateway, I manually switch out which cognito pool the API gateway authenticates and which tables they post to, which isn't very practical.

VDog
  • 1,083
  • 2
  • 13
  • 35
  • If you expose your lambda with API Gateway then just deploy it to two stages - a prod stage which calls the prod lambda which accesses prod Dynamodb & a dev stage which calls dev lambda. In your application, you would just need to change the stage name & you can do so by setting it from Info.plist – agent420 Nov 13 '17 at 19:44
  • Regarding how to get tokens for prod or dev automatically, it depends on how u get these tokens. For example, you could create a /login resource in API Gateway which takes username + password as parameters and returns tokens. Again, deploy it to two stages which use different Cognito pool in the backend calls. Now, you can use the same variable/property in your application to get the stage name for getting tokens too. So, by just changing one property value you can switch between prod & dev in your app – agent420 Nov 13 '17 at 19:48
  • amazing! thanks! Post this as an answer so I can accept it :) – VDog Nov 14 '17 at 19:08
  • glad it worked! – agent420 Nov 14 '17 at 19:59

1 Answers1

1

If you expose your lambda with API Gateway then just deploy it to two stages - a prod stage which calls the prod lambda which accesses prod Dynamodb & a dev stage which calls dev lambda. In your application, you would just need to change the stage name & you can do so by setting it from Info.plist.

Regarding how to get tokens for prod or dev automatically, it depends on how you get these tokens. For example, you could create a /login resource in API Gateway which takes username + password as parameters and returns tokens. Again, deploy it to two stages which use different Cognito pool in the backend calls. Now, you can use the same variable/property in your application to get the stage name for getting tokens too.

So, by just changing the value of one property you can switch between prod & dev in your app.

agent420
  • 3,291
  • 20
  • 27
  • How exactly would I go about having the stage dictate which plist field to choose? Say I have "prod_pool_id" and "dev_pool_id" and the function just reads the plist, and selects one of the two? – VDog Nov 15 '17 at 00:42
  • If you abstract everything behind an Api Gateway then there would be no need to mention prod or dev pool id in your app – agent420 Nov 15 '17 at 01:18
  • even if you do not use api gateway, you can use an if else condition based on stage value to set pool id to Devpoolid or prodpoolid – agent420 Nov 15 '17 at 01:20
  • If you just want a xcode specific solution you can look into user defined build settings. See https://stackoverflow.com/questions/8971488/configuration-dependent-value-in-info-plist-file – agent420 Nov 15 '17 at 01:42