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

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

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

AWS CloudFormation을 통해 템플릿 파일을 사용하여 AWS 리소스 모음을 단일 유닛으로 생성 및 구성할 수 있습니다. 이 섹션은 대기열을 게시하는 주제를 쉽게 배포하는 예제 템플릿을 보여줍니다. 템플릿은 사용자가 두 개의 대기열을 생성하고, 대기열에 대한 주제를 생성하며, 해당 대기열에 정책을 추가하여 주제가 대기열에 메시지를 전송할 수 있도록 하고, 이러한 리소스에 대한 액세스를 제어하는 IAM 사용자 및 그룹을 생성하는 등의 설정 단계에서 사용됩니다.

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

AWS 계정 계정에서 주제 및 대기열 설정을 위한 AWS CloudFormation 템플릿 사용

이 템플릿 예제에서는 주제에 게시할 수 있는 한 IAM 그룹 멤버의 적절한 권한과 대기열에서 메시지를 읽을 수 있는 다른 그룹 멤버의 권한을 사용하여 두 Amazon SQS 대기열에 메시지를 전송할 수 있는 Amazon SNS 주제를 생성합니다. 템플릿은 각 그룹에 추가될 IAM 사용자도 생성합니다.

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

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

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

다음 목록은 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"] } ] ] } } } }