I'm trying to follow best practices and I have two business modules A and B - both with AWS Appsync and IAM.
Now I need to access module B from module A.
So I create HTTP Datasource
(CDK implementation in A module)
const bModuleApiDS = new HttpDataSource(this, 'BModuleApiDS', {
api: this.api,
endpoint: bApiEndpoint,
name: 'BModuleApiDS',
description: `Data source for : ${bApiEndpoint}`,
authorizationConfig: {
signingRegion: 'eu-west-1',
signingServiceName: 'appsync',
},
serviceRole: iam.Role.fromRoleArn(this, 'ServiceRoleForApiDS', bApiRoleArn),
} as unknown as HttpDataSourceProps);
- bApiRoleArn - is defined in B module and adds access to specific queries (IAM authorization)
- bApiEndpoint - appsync url for B module
- "as unknown as HttpDataSourceProps" - for some reason HttpDataSourceProps doesn't expose serviceRole (CDK specific), so this is a way how to force it. (maybe because of my cross account issue?)
All works fine in single account (When module A and module B are in the same account). But when A and B are in different accounts, I'm getting the error: Cross-account pass role is not allowed.
Question: How to setup the role / roles / appsync so it's working when module A and module B are in different AWS accounts?
Another try:
- Deploy without the role (the default role is created)
- Update the role using CLI:
aws appsync update-data-source --api-id kcf4l3xkxxxxxxxcsn6cnfoxm --name BModuleApiDS--type HTTP --service-role-arn arn:aws:iam::9999999999:role/BModuleGraphqlApi-RoleForAModule
I'm getting following error:
An error occurred (AccessDeniedException) when calling the UpdateDataSource operation: Cross-account pass role is not allowed.
- where 999999999999 is B module account
- 111111111111 is A module account
- arn:aws:iam::111111111111:user/cli is the deployment user with admin access and iam:passRole permission
- and BModuleGraphqlApi-RoleForAModule is defined as:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "appsync:GraphQL",
"Resource": "arn:aws:appsync:eu-west-1:999999999999:apis/kcf4l3xkxxxxxxxcsn6cnfoxm/types/Query/fields/queryForModuleA",
"Effect": "Allow"
}
]
}
with trust relationship:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::111111111111:root",
"arn:aws:iam::111111111111:user/cli"
],
"Service": "appsync.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
The same question: How to setup the role / roles / appsync so the module A can access the module B in different AWS account using IAM authorization (not api key)?
Wider context how appsync can simplify access to multiple microservices (https://aws.amazon.com/blogs/mobile/appsync-microservices/)