Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
AWS CloudFormation consente di utilizzare un file modello per creare e configurare una raccolta di AWS risorse insieme come una singola unità. Questa sezione include un modello di esempio in grado di semplificare la distribuzione di argomenti che effettuano pubblicazioni nelle code. I modelli eseguono automaticamente la procedura di configurazione creando due code e un argomento con sottoscrizioni alle code, aggiungendo una policy alle code affinché l'argomento possa inviare messaggi alle code e creando utenti e gruppi IAM per controllare l'accesso a tali risorse.
Per ulteriori informazioni sulla distribuzione AWS delle risorse utilizzando un AWS CloudFormation modello, consulta la Guida introduttiva nella Guida per l'AWS CloudFormation utente.
Utilizzo di un AWS CloudFormation modello per configurare argomenti e code all'interno di un Account AWS
Il modello di esempio crea un argomento Amazon SNS in grado di inviare messaggi a due code Amazon SQS con autorizzazioni appropriate per consentire ai membri di un gruppo IAM di pubblicare nell'argomento e a un altro gruppo di leggere messaggi dalle code. Il modello crea inoltre utenti IAM che vengono aggiunti a ogni gruppo.
Copiare il contenuto del modello in un file. Puoi anche scaricare il modello dalla pagina Modelli.AWS
CloudFormation
My SNSTopic è configurato per pubblicare su due endpoint sottoscritti, che sono due code Amazon SQS MyQueue (1 e 2). MyQueue MyPublishTopicGroup è un gruppo IAM i cui membri sono autorizzati a pubblicare su My SNSTopic utilizzando l'azione Publish API o il comando sns-publish. Il modello crea gli utenti IAM MyPublishUser MyQueueUser e fornisce loro profili di accesso e chiavi di accesso. L'utente che crea uno stack con questo modello specifica le password per i profili di accesso come parametri di input. Il modello crea chiavi di accesso per i due utenti IAM con MyPublishUserKey e MyQueueUserKey. AddUserToMyPublishTopicGroup si aggiunge MyPublishUser a MyPublishTopicGroup in modo che all'utente vengano assegnate le autorizzazioni al gruppo.
My RDMessage QueueGroup è un gruppo IAM i cui membri sono autorizzati a leggere ed eliminare messaggi dalle due code di Amazon SQS utilizzando le azioni ReceiveMessagee DeleteMessageAPI. AddUserToMyQueueGroup si aggiunge MyQueueUser a My RDMessage QueueGroup in modo che all'utente vengano assegnate le autorizzazioni al gruppo. MyQueuePolicy assegna il permesso SNSTopic a My di pubblicare le sue notifiche nelle due code.
L'elenco seguente mostra il contenuto del AWS CloudFormation modello.
{
"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"]
}
]
]
}
}
}
}