Hello :wave: I'm considering using SST for a new p...
# help
j
Hello 👋 I'm considering using SST for a new project and one of my requirements will be to provision AWS resources dynamically for customers e.g. each customer would have their own deployed lambdas / dynamoDB tables etc... I'm wondering if there is any prior art in using SST/CDK from inside a lambda?
o
We do this a little bit, but not dynamically. Have a CustomerStack construct and just deploy a new version with an extra line in our SST index adding a new instance. This is only done for customers who have upgraded to prod, trials and sandbox tenants use shared infra. One we open up public sign up, we'll have to figure out how to make that a product feature instead of it being part of the infra code, but works well enough for now
t
The way Omi has it is the only way I'd probably recommend, managing it manually to start and letting ot go through your normal Ci pipeline
if you want something entirely self serve I'd consider looking into generating cloudformation templates and applying them directly. As of now it's pretty messy to call CDK dynamically and probably wouldn't suggest absorbing that complexity
Third option would be cloud control API but that means using a completely different system
o
Yeah the product feature version would probably just use the AWS SDK to CRUD new DB instances/tables etc, have it store state in a platform DB. Maybe use step functions for orchestrating deployments. Would need some features to handle migrations, track the current vs expected state of the resources, and make sure the app’s data model is updated as needed etc. Also I’d only do this for sharded storage, every other infra layer would be shared across tenants (lambdas, apigws, etc).
Thanks for the tip on cloud control API, looks like exactly what I’d need
c
Interesting to hear other peoples approach to this. Our approach is similar to @Omi Chowdhury. We have a customer config file and then on each deploy loop through the file and create/update a customer stack depending on this content. When we add a new customer we add an entry to the config file and then just deploy that customer stack. Its working so far but we're very dependent on good CI/CD. So Customer config is like:
Copy code
[
  {
    "ID": 11,
    "UUID": "19bc08d4-88b5-4cf8-ae5f-e654c4bf893d",
    "Name": "ACME Inc.",
    "Enabled": true,
    "S3Bucket": "uniquebucket-56b50609-21f8-4647-8c7f-4a649f86f759",
    "DefaultResourceOwner": "927d454b-072f-4961-a8a4-589683ec1201"
  },
  {
...
]
And then our CDK is:
Copy code
import TenantConfig from '../configs/tenants.json';

...

    if (TenantConfig.length != 0) {
      Object.values(TenantConfig).map(
        (config : {[k: string]: string|number|boolean}) => {
        
          new TenantStack(this, `TenantStack-${String(config["UUID"])}`, {
            environment: props.environment,
            env: props.env,
            tenantId: String(config["UUID"]),
            tenantConfig: config,
            ...
          })
        }
      )
    }
j
Ok so sounds like generating cloudformation and using the CF API might be the way to go for my needs. I guess once I've figured out the right CF templates this will work ok. Still looking forward to using SST for our infra though 🙂