Giorgio
04/26/2022, 11:23 PMconst auth = new sst.Auth(this, 'Auth');
const api = new sst.AppSyncApi(this, 'Api', {
cdk: {
graphqlApi: {
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.IAM
},
additionalAuthorizationModes: [{
authorizationType: appsync.AuthorizationType.USER_POOL,
userPoolConfig: {
auth.cdk.userPool,
defaultAction: appsync.UserPoolDefaultAction.DENY,
},
}]
},
},
},
});
api.cdk.graphqlApi.grantQuery(auth.cdk.unauthRole, 'nameOfMyQuery');
The error I'm getting is:
Error: 'dev-my-app-auth' depends on 'dev-my-app-api' (dev-my-app-auth -> dev-my-app-api/GraphqlApi/Api/Resource.ApiId). Adding this dependency (dev-my-app-api -> dev-my-app-auth/Auth/UserPool/Resource.Ref) would create a cyclic reference.
Is there any other way to set this up? What I'm basically trying to do is to set up the AppSync API to have both authenticated access via user pool and a single query to have unauthenticated access.Derek Kershner
04/27/2022, 3:25 AMAuth
to ssm
, and use them how you see fit in the API stack.
This is a more complex pattern to be sure, but likely one worth learning, as splitting into smaller stacks saves many headaches.Giorgio
04/27/2022, 3:47 AMDerek Kershner
04/27/2022, 3:50 AMGiorgio
04/27/2022, 3:56 AMDerek Kershner
04/27/2022, 3:59 AM.from
methods. I think for roles it might be fromRoleArn
Derek Kershner
04/27/2022, 4:00 AMGiorgio
04/27/2022, 4:17 AMFrank
Giorgio
05/27/2022, 7:20 AMsst start
run.Giorgio
05/27/2022, 7:23 AMAuthStack.ts
it calls:
const unauthRoleARNParamName = `/${app.name}/${app.stage}/unauthRoleARN`;
new ssm.StringParameter(stack, 'unauthRoleARN', {
parameterName: unauthRoleARNParamName,
stringValue: auth.cdk.unauthRole.roleArn,
});
return {
unauthRoleARNParamName,
};
and in ApiStack.ts
it will fetch it by:
const { unauthRoleARNParamName } = use(AuthStack);
const unauthRoleARN = ssm.StringParameter.valueFromLookup(stack, unauthRoleARNParamName);
const unauthRole = iam.Role.fromRoleArn(stack, 'unauthRole', unauthRoleARN);
api.cdk.graphqlApi.grantQuery(unauthRole, 'myQuery');
Giorgio
05/27/2022, 7:25 AM