简体   繁体   English

从 Lambda 向 SQS 发送跨 AWS 账户消息

[英]Send cross AWS account message from Lambda to SQS

I want to send a message to SQS queue on another account (Ohio) from lambda in North Virginia account.我想从北弗吉尼亚帐户的 lambda 向另一个帐户(俄亥俄州)的 SQS 队列发送消息。 How can I achieve this?我怎样才能做到这一点?

Things I tried so far:到目前为止我尝试过的事情:

  1. Created a queue in Ohio and gave lambda role arn to the queue.在俄亥俄州创建了一个队列,并将 lambda 角色分配给队列。

  2. Sent message from the lambda in North Virigina, got following error:从 North Virigina 的 lambda 发送消息,出现以下错误:

    "errorMessage": "An error occurred (AWS.SimpleQueueService.NonExistentQueue) when calling the SendMessage operation: "errorMessage": "调用 SendMessage 操作时发生错误 (AWS.SimpleQueueService.NonExistentQueue):

If you are sending cross-account messages, you have to do the following things.如果您要发送跨帐户消息,则必须执行以下操作。

  1. In the account where the queue exists, you have to create an SQS access policy for the queue in order to allow for the other account to be able to send messages.在队列所在的账户中,您必须为队列创建 SQS 访问策略,以允许其他账户能够发送消息。 I queue policy might look like this:我的队列策略可能如下所示:
{
    "Version": "2012-10-17",
    "Id": "Queue1_Policy_UUID",
    "Statement": [
        {
            "Sid": "Queue1_AllActions",
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::111122223333:role/lambdaRole"
                ]
            },
            "Action": [
                "sqs:SendMessage",
                "sqs:ReceiveMessage"
            ],
            "Resource": "arn:aws:sqs:us-east-2:123456789012:queue1"
        }
    ]
}

The principal here is the Lambda role from the account where the Lambda is deployed.此处的主体是部署 Lambda 的帐户中的 Lambda 角色。

  1. For your Lambda role you have to give permission to be able to send SQS messages to the queue from the other account (according to your question, you already did this).对于您的 Lambda 角色,您必须授予能够从其他帐户向队列发送 SQS 消息的权限(根据您的问题,您已经这样做了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM