AWS Lambda找不到明显存在的SNS话题?

2024-04-19 10:45:16 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我通过控制台创建了一个SNS主题,然后尝试调用list_subscriptions_by_topicsns.publish,但都失败了,因为

An error occurred (NotFound) when calling the Publish 
operation: Topic does not exist: NotFoundException

那么是什么给了???在SNS控制台中可以访问该主题。你知道吗

这是我的lambda代码:

from __future__ import print_function

import json
import boto3
import random


print('Loading function')
sns = boto3.client('sns')

def lambda_handler(event, context):

    response = sns.publish(
        TopicArn='arn:aws:sns:us-west-2:031436316123:topicExists' 
        Message=json.dumps(newMsg),
        MessageAttributes={
            'event_type':{
                'DataType':'String', 'StringValue':'something'

            }
        }
    )


    return response

它是订阅topicExistsSNS主题的SQS上的Lambda触发器集。你知道吗


Tags: lambdaimporteventjson主题byresponsesubscriptions
1条回答
网友
1楼 · 发布于 2024-04-19 10:45:16

问题是SNS主题存在于us-west-2区域中,但是您的SNS客户端正在us-east-1区域中创建。你知道吗

此行没有指定区域,因此默认情况下在us-east-1中创建:

sns = boto3.client('sns')

应将其替换为:

sns = boto3.client('sns', region_name='us-west-2')

相关问题 更多 >