Ich habe eine cloudformation
Vorlage, um eine Lambda-Funktion und ein SNS-Thema zu erstellen. Die Lambda-Funktion führt eine Verarbeitung durch und veröffentlicht das Ergebnis im SNS-Thema.Erteilen Sie AWS Lambda die Berechtigung, alle SNS-Themen aufzulisten
Um den ARN des SNS-Themas zu erhalten, verwende ich die boto3.client('sns').list_topics()
-Funktion und suche dann nach dem SNS-Themennamen, den ich in der Vorlage eingestellt habe.
Aber Aufruf der list_topics()
API mir folgende Fehler geben:
An error occurred (AuthorizationError) when calling the ListTopics operation: User: arn:aws:sts::136732452473:assumed-role/test/severless-btc-update-PriceUpdateFunction-B38KNZMCBGB is not authorized to perform: SNS:ListTopics on resource: arn:aws:sns:eu-west-1:136732452473:*
Wie kann ich die ListTopics Erlaubnis meiner Lambda-Ressource in der Cloudformation Template YAML-Datei hinzufügen?
Das ist meine cloudformation.yaml Datei:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Bitcoin daily update
Parameters:
PhoneNumber:
Type: String
Description: The phone number recipient of the update, in E.164 (e.g. +919876123456) format.
UTCHour:
Type: String
Default: 3
Description: The hour at which to send the update, in the UTC time zone.
Resources:
PriceUpdateFunction:
Type: AWS::Serverless::Function
Properties:
Handler: main.lambda_handler
Runtime: python3.6
Timeout: 5
CodeUri: main.py
Environment:
Variables:
PHONE_NUMBER: !Ref PhoneNumber
Events:
ScheduledEvent:
Type: Schedule
Properties:
Schedule: !Join [' ', ['cron(0', !Ref UTCHour, '* * ? *)']]
Policies:
- SNSPublishMessagePolicy:
TopicName: !GetAtt SNSTopic.TopicName
SNSTopic:
Type: "AWS::SNS::Topic"
Properties:
TopicName: "sendSMS"
DisplayName: "BitcoinPriceTopic"
Subscription:
-
Endpoint: !Ref PhoneNumber
Protocol: "sms"