AWS CloudFormation 템플릿을 사용하여 Amazon SQS 대기열로 메시지를 보내는 주제 생성 - Amazon Simple Notification Service

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS CloudFormation 템플릿을 사용하여 Amazon SQS 대기열로 메시지를 보내는 주제 생성

AWS CloudFormation 를 사용하면 템플릿 파일을 사용하여 리소스 컬렉션을 AWS 단일 단위로 함께 생성하고 구성할 수 있습니다. 이 섹션은 대기열을 게시하는 주제를 쉽게 배포하는 예제 템플릿을 보여줍니다. 템플릿은 두 개의 대기열을 생성하고, 대기열에 대한 구독이 있는 주제를 생성하고, 대기열에 정책을 추가하여 주제가 대기열에 메시지를 보낼 수 있도록 하고, 이러한 리소스에 대한 액세스를 제어하는 IAM 사용자 및 그룹을 생성하여 설정 단계를 처리합니다.

AWS CloudFormation 템플릿을 사용하여 AWS 리소스를 배포하는 방법에 대한 자세한 내용은 AWS CloudFormation 사용 설명서시작하기를 참조하세요.

AWS CloudFormation 템플릿을 사용하여 내에서 주제 및 대기열 설정 AWS 계정

예제 템플릿은 한 IAM 그룹의 멤버가 SNS 주제에 게시하고 다른 멤버가 SQS 대기열에서 메시지를 읽을 수 있는 적절한 권한이 있는 두 개의 Amazon 대기열로 메시지를 보낼 수 있는 Amazon 주제를 생성합니다. 또한 템플릿은 각 그룹에 추가되는 IAM 사용자를 생성합니다.

템플릿 콘텐츠를 파일에 복사합니다. 템플릿 AWS 페이지에서 CloudFormation 템플릿을 다운로드할 수도 있습니다. 템플릿 페이지에서 AWS 서비스별 샘플 템플릿 찾아보기를 선택한 다음 Amazon Simple Queue Service를 선택합니다.

MySNSTopic 은 두 개의 구독 엔드포인트, 즉 두 개의 Amazon SQS 대기열(MyQueue1 및 MyQueue2)에 게시하도록 설정됩니다. MyPublishTopicGroup 는 멤버가 게시 API 작업 또는 sns-publish 명령을 ySNSTopic 사용하여 M에 게시할 수 있는 권한이 있는 IAM 그룹입니다. 템플릿은 IAM 사용자를 생성하고 로그인 프로필 MyPublishUser MyQueueUser 과 액세스 키를 제공합니다. 이 템플릿으로 스택을 생성한 사용자는 로그인 프로필에 입력 파라미터로 암호를 지정합니다. 템플릿은 MyPublishUserKey 및 이 있는 두 IAM 사용자에 대한 액세스 키를 생성합니다 MyQueueUserKey. MyPublishUser MyPublishTopicGroup는 사용자에게 그룹에 할당된 권한을 부여하도록 에 를 AddUserToMyPublishTopicGroup 추가합니다.

MyRDMessageQueueGroup 은 멤버가 ReceiveMessageDeleteMessage API 작업을 사용하여 두 Amazon SQS 대기열에서 메시지를 읽고 삭제할 수 있는 권한이 있는 IAM 그룹입니다. AddUserToMyQueueGroup yRDMessageQueueGroup 사용자가 그룹에 할당된 권한을 갖도록 가 M MyQueueUser 에 를 추가합니다. 는 M이 두 대기열에 알림을 게시ySNSTopic 할 수 있는 권한을 MyQueuePolicy 할당합니다.

다음 목록은 AWS CloudFormation 템플릿 내용을 보여줍니다.

{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "AWS CloudFormation Sample Template SNSToSQS: This Template creates an SNS topic that can send messages to two SQS queues with appropriate permissions for one IAM user to publish to the topic and another to read messages from the queues. MySNSTopic is set up to publish to two subscribed endpoints, which are two SQS queues (MyQueue1 and MyQueue2). MyPublishUser is an IAM user that can publish to MySNSTopic using the Publish API. MyTopicPolicy assigns that permission to MyPublishUser. MyQueueUser is an IAM user that can read messages from the two SQS queues. MyQueuePolicy assigns those permissions to MyQueueUser. It also assigns permission for MySNSTopic to publish its notifications to the two queues. The template creates access keys for the two IAM users with MyPublishUserKey and MyQueueUserKey. ***Warning*** you will be billed for the AWS resources used if you create a stack from this template.", "Parameters": { "MyPublishUserPassword": { "NoEcho": "true", "Type": "String", "Description": "Password for the IAM user MyPublishUser", "MinLength": "1", "MaxLength": "41", "AllowedPattern": "[a-zA-Z0-9]*", "ConstraintDescription": "must contain only alphanumeric characters." }, "MyQueueUserPassword": { "NoEcho": "true", "Type": "String", "Description": "Password for the IAM user MyQueueUser", "MinLength": "1", "MaxLength": "41", "AllowedPattern": "[a-zA-Z0-9]*", "ConstraintDescription": "must contain only alphanumeric characters." } }, "Resources": { "MySNSTopic": { "Type": "AWS::SNS::Topic", "Properties": { "Subscription": [{ "Endpoint": { "Fn::GetAtt": ["MyQueue1", "Arn"] }, "Protocol": "sqs" }, { "Endpoint": { "Fn::GetAtt": ["MyQueue2", "Arn"] }, "Protocol": "sqs" } ] } }, "MyQueue1": { "Type": "AWS::SQS::Queue" }, "MyQueue2": { "Type": "AWS::SQS::Queue" }, "MyPublishUser": { "Type": "AWS::IAM::User", "Properties": { "LoginProfile": { "Password": { "Ref": "MyPublishUserPassword" } } } }, "MyPublishUserKey": { "Type": "AWS::IAM::AccessKey", "Properties": { "UserName": { "Ref": "MyPublishUser" } } }, "MyPublishTopicGroup": { "Type": "AWS::IAM::Group", "Properties": { "Policies": [{ "PolicyName": "MyTopicGroupPolicy", "PolicyDocument": { "Statement": [{ "Effect": "Allow", "Action": [ "sns:Publish" ], "Resource": { "Ref": "MySNSTopic" } }] } }] } }, "AddUserToMyPublishTopicGroup": { "Type": "AWS::IAM::UserToGroupAddition", "Properties": { "GroupName": { "Ref": "MyPublishTopicGroup" }, "Users": [{ "Ref": "MyPublishUser" }] } }, "MyQueueUser": { "Type": "AWS::IAM::User", "Properties": { "LoginProfile": { "Password": { "Ref": "MyQueueUserPassword" } } } }, "MyQueueUserKey": { "Type": "AWS::IAM::AccessKey", "Properties": { "UserName": { "Ref": "MyQueueUser" } } }, "MyRDMessageQueueGroup": { "Type": "AWS::IAM::Group", "Properties": { "Policies": [{ "PolicyName": "MyQueueGroupPolicy", "PolicyDocument": { "Statement": [{ "Effect": "Allow", "Action": [ "sqs:DeleteMessage", "sqs:ReceiveMessage" ], "Resource": [{ "Fn::GetAtt": ["MyQueue1", "Arn"] }, { "Fn::GetAtt": ["MyQueue2", "Arn"] } ] }] } }] } }, "AddUserToMyQueueGroup": { "Type": "AWS::IAM::UserToGroupAddition", "Properties": { "GroupName": { "Ref": "MyRDMessageQueueGroup" }, "Users": [{ "Ref": "MyQueueUser" }] } }, "MyQueuePolicy": { "Type": "AWS::SQS::QueuePolicy", "Properties": { "PolicyDocument": { "Statement": [{ "Effect": "Allow", "Principal": { "Service": "sns.amazonaws.com" }, "Action": ["sqs:SendMessage"], "Resource": "*", "Condition": { "ArnEquals": { "aws:SourceArn": { "Ref": "MySNSTopic" } } } }] }, "Queues": [{ "Ref": "MyQueue1" }, { "Ref": "MyQueue2" }] } } }, "Outputs": { "MySNSTopicTopicARN": { "Value": { "Ref": "MySNSTopic" } }, "MyQueue1Info": { "Value": { "Fn::Join": [ " ", [ "ARN:", { "Fn::GetAtt": ["MyQueue1", "Arn"] }, "URL:", { "Ref": "MyQueue1" } ] ] } }, "MyQueue2Info": { "Value": { "Fn::Join": [ " ", [ "ARN:", { "Fn::GetAtt": ["MyQueue2", "Arn"] }, "URL:", { "Ref": "MyQueue2" } ] ] } }, "MyPublishUserInfo": { "Value": { "Fn::Join": [ " ", [ "ARN:", { "Fn::GetAtt": ["MyPublishUser", "Arn"] }, "Access Key:", { "Ref": "MyPublishUserKey" }, "Secret Key:", { "Fn::GetAtt": ["MyPublishUserKey", "SecretAccessKey"] } ] ] } }, "MyQueueUserInfo": { "Value": { "Fn::Join": [ " ", [ "ARN:", { "Fn::GetAtt": ["MyQueueUser", "Arn"] }, "Access Key:", { "Ref": "MyQueueUserKey" }, "Secret Key:", { "Fn::GetAtt": ["MyQueueUserKey", "SecretAccessKey"] } ] ] } } } }