람다 함수 및 SNS 주제를 만들기 위해 cloudformation
템플릿이 있습니다. 람다 함수는 일부 처리를 수행하고 결과를 SNS 주제에 게시합니다.AWS 람다에게 모든 SNS 주제를 나열 할 수있는 권한 부여
SNS 주제의 ARN을 얻으려면 boto3.client('sns').list_topics()
함수를 사용하고 템플릿에 설정 한 SNS 주제 이름을 검색하고 있습니다.
그러나 list_topics()
API 나에게 다음과 같은 오류주고 전화 : 나는 cloudformation 템플릿 YAML 파일에 내 람다 리소스에 ListTopics 권한을 추가 할 수있는 방법
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:*
를?
이 내 cloudformation.yaml 파일입니다 : 당신은 람다 실행 역할을 정의하고 함수에 적절한 권한을 할당해야
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"