can anyone help explain permissions in SST/CDK? ``...
# general
s
can anyone help explain permissions in SST/CDK?
Copy code
import * as dynamodb from "@aws-cdk/aws-dynamodb";

const sns = new sns.Topic(this, "Topic");
const table = new dynamodb.Table(this, "Table");

fun.attachPermissions([
  [topic, "grantPublish"],
  [table, "grantReadData"],
]);
this code is from https://docs.serverless-stack.com/constructs/Function#attachpermissions. how would I know
grantPublish
is a thing? is there a reference somewhere?
t
I believe those just reference functions that are on the base construct
If you explore topic.grant* you'll see what's available. We can probably do some typescript magic to make this more discoverable
s
I’m trying to figure out how to set up custom email senders in Cognito (which trigger Lambda funcs). the AWS docs say I have to grant Cognito service principal access to invoke the Lambda func, using this command:
aws lambda add-permission --function-name lambda_arn --statement-id "CognitoLambdaInvokeAccess" --action lambda:InvokeFunction --principal <http://cognito-idp.amazonaws.com|cognito-idp.amazonaws.com>
how would I do that in SST?
Copy code
auth.attachPermissionsForTriggers([
    new iam.PolicyStatement({
      effect: iam.Effect.ALLOW,
      principals: [new iam.ServicePrincipal('<http://cognito-idp.amazonaws.com|cognito-idp.amazonaws.com>')],
      actions: ['lambda:InvokeFunction'],
    }),
  ]);
🤔 this looks correct.. I think. just missing the resource
t
can you try this
Copy code
function.grantInvoke(new iam.ServicePrincipal("<http://cognito-idp.amazonaws.com|cognito-idp.amazonaws.com>"))
Unfortunately not super familiar with this flow
s
@thdxr nice, thanks! much more terse. I’ll see how that works out once this stack is more fully fleshed out and it actually does something 😄