The ideal way of handling different environments (especially for serverless) is having multiple AWS accounts under the same organization(AWS Organizations) where you have a separate account for staging and another account for production.
So in case if you want to solve this within a single account, you can either use SSM parameter or Mappings in SAM template.
Referencing existing system manager param
Parameters:
ApiBaseUrl :
Type : 'AWS::SSM::Parameter::Value<String>'
Default: /${paramEnvironment}/apiBaseUrl
By mappings in SAM template
Mappings:
EnvVariables:
stage:
var1: user1
API_BASE_URL: https://baseurl1.com
prod:
var1: user2
API_BASE_URL: https://baseurl2.com
and refer the map using,
!FindInMap [ EnvVariables, ${paramEnvironment}, API_BASE_URL ]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…