Textract completion msg not published to SNS Topic using Cognito user
I have read the instructions https://docs.aws.amazon.com/textract/latest/dg/api-async-roles.html#api-async-roles-all-topics . My set up is somewhat different because I am using a Cognito user. To enable textract to publish msg to SNS, I pass relevant permissions to Textract to enable it to call SNS. I am able to call StartDocumentAnalysis method and get a response. But the SNS message is never published. The weird thing is that on a few occasions I did see the several data points in CloudWatch's SNS Metric - 'NumberOfNotificationsDelivered', indicating that the messages were published. However, they are almost all gone now. What is wrong with the below?
The cognito authorized user has the CognitoAuthRole role:
CognitoAuthRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Federated: cognito-identity.amazonaws.com
Action: sts:AssumeRoleWithWebIdentity
Condition:
StringEquals:
cognito-identity.amazonaws.com:aud: !Ref CoginitoIdentityPool
ForAnyValue:StringLike:
cognito-identity.amazonaws.com:amr: authenticated
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
- Effect: Allow
Principal:
Service: textract.amazonaws.com
Action: sts:AssumeRole
Description: Used by cognito authenticated users
ManagedPolicyArns:
- !Ref DesktopPolicy #definition is immediately below
And the desktop policy is:
DesktopPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: DesktopBackup
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'iam:GetRole'
- 'iam:PassRole'
Resource: !GetAtt "TextractEc2Role.Arn" #definition is below
- Effect: Allow
Action:
- "sns:Publish"
Resource:
- arn:aws:sns:us-east-1:xxxxxxxxxxxx:AmazonTextractTopic
- Effect: Allow
Action:
- "textract:GetDocumentAnalysis"
- "textract:GetDocumentTextDetection"
- "textract:StartDocumentAnalysis"
- "textract:StartDocumentTextDetection"
Resource:
- "*"
The role that is passed to Textract service using iam:PassRole is:
TextractEc2Role:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: textract.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
- arn:aws:iam::aws:policy/AmazonSNSFullAccess
- arn:aws:iam::aws:policy/AmazonTextractFullAccess
- arn:aws:iam::aws:policy/service-role/AmazonTextractServiceRole
RoleName: TextractEc2
Edited by: L Jones on Sep 1, 2020 6:40 PM
Edited by: L Jones on Sep 1, 2020 6:41 PM
I found the the issue. When using the .NET API (or any other API), there is no need to specify "iam:PassRole" for the user. The API has the ability to specify both the role Textract needs to call SNS and also which topic to send completion message. See .NET solution below
NotificationChannel channel = new NotificationChannel();
channel.RoleArn = MY_TEXTRACT_SNS_ROLE_ARN;
channel.SNSTopicArn = MY_TEXTRACT_SNS_TOPIC_ARN;
request.NotificationChannel = channel;
Where MY_TEXTRACT_SNS_TOPIC_ARN is an SNS topic that must begin with 'AmazonTextract'. Ex: AmazonTextractMyTopic
Where MY_TEXTRACT_SNS_ROLE_ARN is the ARN for:
TextractSnsRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: textract.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns: - arn:aws:iam::aws:policy/service-role/AmazonTextractServiceRole
RoleName: TextractSns
Relevant questions
How to setup email alerts to my cloudwatch alarms
asked 5 months agoCloudWatch Alarm permission issue with cross account KMS encrypted SNS Topic
asked 2 months agoCan we send email notifications from SNS using our own domain?
Accepted Answerasked 2 months agoTextract using FIFO SNS topics and FIFO SQS queues
asked a year agoconfigservice subscribe requires sns-topic, but console does not
asked 3 years agoTextract completion msg not published to SNS Topic using Cognito user
asked 2 years agoCreating an SNS Topic Resource by CF Template Not Working
asked 2 years agoSystems Manager Change Manager Notifications not working
asked a month agoSQS not receiving SNS message
asked 3 years agoAWS Sns Publish method is not working when application deployed using docker container
asked 2 months ago