sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.12k stars 136 forks source link

Trying to link a Cognito User Pool #319

Closed thelegendtubaguy closed 2 months ago

thelegendtubaguy commented 2 months ago

I'm following the monorepo design such that my folder structure looks like this:

image

I have several different functions in my functions package, each with mostly unique "links" to other resources. I've defined one like so:

const connectionFunction = new sst.aws.Function('ConnectionFunction', {
    handler: './packages/functions/src/ApiConnection.handler',
    link: [apiTable, bus, userPool ],
    memory: '128 MB',
    timeout: '10 seconds',
})

However when I ran this lambda I was told that "UserPool" was not linked (the resource name on userPool). The sst-env.d.ts is mysteriously missing any reference to "UserPool".

import "sst"
declare module "sst" {
  export interface Resource {
    ApiTable: {
      name: string
      type: "sst.aws.Dynamo"
    }
    EventsTable: {
      name: string
      type: "sst.aws.Dynamo"
    }
  }
}
export {}

Do I need to have the same link on every function to get this to show up? I don't really want to give permissions to my user pool to every function if they don't need it. Thanks!

And thank you for introducing me to Pulumi. Working with this has been such a dream compared to CDK.

thelegendtubaguy commented 2 months ago

Oh my userPool is a Pulumi resource, not an SST Ion component. I'm going to guess that's it :D

thelegendtubaguy commented 2 months ago

I have switched to the very newly released CognitoUserPool SST component and it still isn't linking. Maybe I'm just too early to using it? It is not listed under link in state edit.

fwang commented 2 months ago

Hey @thelegendtubaguy what r u trying to do w/ the user pool in ConnectionFunction?

thelegendtubaguy commented 2 months ago

It'd be nice to access the user pool ID. The function is specifically doing list users, update user attributes, and add user to groups.

I was able to work around this by specifying permissions on the function and setting the user pool id as an env var for now.

fwang commented 2 months ago

Added in v0.0.325.

Now when u link CognitoUserPool, you can access Resource.MyUserPool.id, and the function has cognito-idp:* permission on the user pool arn.

Feel free to reopen if this doesn't work for you.

thelegendtubaguy commented 2 months ago

Awesome! Thank you!