Hello, I’m working on migrating a serverless frame...
# help
j
Hello, I’m working on migrating a serverless framework service to SST and am struggling to figure out how to reference already existing resources within SST. For example, in my serverless.yml file, I reference stage dependent ddb tables like so:
Copy code
provider:
  environment:
    myTableName: ${cf:myOtherService-${self:provider.stage}.TableName}
Then I dereference
myTableName
from
process.env
within the lambda. What is the best way to do this within SST?
r
j
Is there a recommended way to do this that dynamically references the correct ARN depending on the stage?
s
A few ways come to mind. 1. Define
.env
files for each environment (stage/prod/etc) and list the ARNs there. You could then import based on the value in the environment variable. For example:
Copy code
new Table(this, "Table", {
  dynamodbTable:dynamodb.Table.fromTableArn(this, "ImportedTable", process.env.TableArn), 
});
More info here. 2. Save the ARNs to a shared environment like AWS Parameter Store with names that are defined by stage. For example, you could have parameters named
/prod/my_service/table_arn
,
/stage/my_service/table_arn
j
Thanks Seth! The staged .env files seems like the route to go for our use case
s
Yeah, it's a pretty nice feature