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à.
Eliminazione di un SNS argomento e di un abbonamento Amazon
Quando un argomento viene eliminato, gli abbonamenti associati vengono eliminati in modo asincrono. Sebbene i clienti possano ancora accedere a questi abbonamenti, gli abbonamenti non sono più associati all'argomento, anche se si ricrea l'argomento utilizzando lo stesso nome.
Se un editore tenta di pubblicare un messaggio sull'argomento eliminato, riceverà un messaggio di errore che indica che l'argomento non esiste. Analogamente, qualsiasi tentativo di abbonamento all'argomento eliminato genererà anche un messaggio di errore.
Non è possibile eliminare un abbonamento in attesa di conferma. Amazon elimina SNS automaticamente gli abbonamenti non confermati dopo 48 ore.
Per eliminare un SNS argomento o un abbonamento Amazon utilizzando il AWS Management Console
Per eliminare un argomento utilizzando il AWS Management Console
Accedi alla SNSconsole Amazon.
-
Nel pannello di navigazione a sinistra, selezionare Topics (Argomenti).
-
Nella pagina Topics (Argomenti), selezionare un argomento e scegliere Elimina.
-
Nella finestra di dialogo Delete topic (Elimina argomento), digitare delete
me
, quindi selezionare Delete (Elimina).
La console elimina l'argomento.
Per eliminare un abbonamento utilizzando il AWS Management Console
Accedi alla SNSconsole Amazon.
-
Nel pannello di navigazione sinistro scegli Sottoscrizioni.
-
Nella pagina Abbonamenti, seleziona un abbonamento con lo stato Confermato, quindi scegli Elimina.
-
Nella finestra di dialogo Delete subscription (Elimina iscrizione), scegliere Delete (Elimina).
La console elimina la sottoscrizione.
Per eliminare un abbonamento e un argomento utilizzando un AWS SDK
Per utilizzare un AWS SDK, è necessario configurarlo con le proprie credenziali. Per ulteriori informazioni, consulta I file di configurazione e credenziali condivisi nella AWS SDKs and Tools Reference Guide.
I seguenti esempi di codice mostrano come utilizzare. DeleteTopic
- .NET
-
- AWS SDK for .NET
-
Elimina un argomento per argomentoARN.
/// <summary>
/// Delete a topic by its topic ARN.
/// </summary>
/// <param name="topicArn">The ARN of the topic.</param>
/// <returns>True if successful.</returns>
public async Task<bool> DeleteTopicByArn(string topicArn)
{
var deleteResponse = await _amazonSNSClient.DeleteTopicAsync(
new DeleteTopicRequest()
{
TopicArn = topicArn
});
return deleteResponse.HttpStatusCode == HttpStatusCode.OK;
}
- C++
-
- SDKper C++
-
//! Delete an Amazon Simple Notification Service (Amazon SNS) topic.
/*!
\param topicARN: The Amazon Resource Name (ARN) for an Amazon SNS topic.
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool AwsDoc::SNS::deleteTopic(const Aws::String &topicARN,
const Aws::Client::ClientConfiguration &clientConfiguration) {
Aws::SNS::SNSClient snsClient(clientConfiguration);
Aws::SNS::Model::DeleteTopicRequest request;
request.SetTopicArn(topicARN);
const Aws::SNS::Model::DeleteTopicOutcome outcome = snsClient.DeleteTopic(request);
if (outcome.IsSuccess()) {
std::cout << "Successfully deleted the Amazon SNS topic " << topicARN << std::endl;
}
else {
std::cerr << "Error deleting topic " << topicARN << ":" <<
outcome.GetError().GetMessage() << std::endl;
}
return outcome.IsSuccess();
}
- CLI
-
- AWS CLI
-
Per eliminare un SNS argomento
L'delete-topic
esempio seguente elimina l'SNSargomento specificato.
aws sns delete-topic \
--topic-arn "arn:aws:sns:us-west-2:123456789012:my-topic"
Questo comando non produce alcun output.
- Go
-
- SDKper Go V2
-
// SnsActions encapsulates the Amazon Simple Notification Service (Amazon SNS) actions
// used in the examples.
type SnsActions struct {
SnsClient *sns.Client
}
// DeleteTopic delete an Amazon SNS topic.
func (actor SnsActions) DeleteTopic(topicArn string) error {
_, err := actor.SnsClient.DeleteTopic(context.TODO(), &sns.DeleteTopicInput{
TopicArn: aws.String(topicArn)})
if err != nil {
log.Printf("Couldn't delete topic %v. Here's why: %v\n", topicArn, err)
}
return err
}
- Java
-
- SDKper Java 2.x
-
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.DeleteTopicRequest;
import software.amazon.awssdk.services.sns.model.DeleteTopicResponse;
import software.amazon.awssdk.services.sns.model.SnsException;
/**
* Before running this Java V2 code example, set up your development
* environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*/
public class DeleteTopic {
public static void main(String[] args) {
final String usage = """
Usage: <topicArn>
Where:
topicArn - The ARN of the topic to delete.
""";
if (args.length != 1) {
System.out.println(usage);
System.exit(1);
}
String topicArn = args[0];
SnsClient snsClient = SnsClient.builder()
.region(Region.US_EAST_1)
.build();
System.out.println("Deleting a topic with name: " + topicArn);
deleteSNSTopic(snsClient, topicArn);
snsClient.close();
}
public static void deleteSNSTopic(SnsClient snsClient, String topicArn) {
try {
DeleteTopicRequest request = DeleteTopicRequest.builder()
.topicArn(topicArn)
.build();
DeleteTopicResponse result = snsClient.deleteTopic(request);
System.out.println("\n\nStatus was " + result.sdkHttpResponse().statusCode());
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
}
- JavaScript
-
- SDKper JavaScript (v3)
-
Creare il client in un modulo separato ed esportarlo.
import { SNSClient } from "@aws-sdk/client-sns";
// The AWS Region can be provided here using the `region` property. If you leave it blank
// the SDK will default to the region set in your AWS config.
export const snsClient = new SNSClient({});
Importa i moduli SDK e client e chiama ilAPI.
import { DeleteTopicCommand } from "@aws-sdk/client-sns";
import { snsClient } from "../libs/snsClient.js";
/**
* @param {string} topicArn - The ARN of the topic to delete.
*/
export const deleteTopic = async (topicArn = "TOPIC_ARN") => {
const response = await snsClient.send(
new DeleteTopicCommand({ TopicArn: topicArn }),
);
console.log(response);
// {
// '$metadata': {
// httpStatusCode: 200,
// requestId: 'a10e2886-5a8f-5114-af36-75bd39498332',
// extendedRequestId: undefined,
// cfId: undefined,
// attempts: 1,
// totalRetryDelay: 0
// }
// }
};
- Kotlin
-
- SDKper Kotlin
-
suspend fun deleteSNSTopic(topicArnVal: String) {
val request =
DeleteTopicRequest {
topicArn = topicArnVal
}
SnsClient { region = "us-east-1" }.use { snsClient ->
snsClient.deleteTopic(request)
println("$topicArnVal was successfully deleted.")
}
}
- PHP
-
- SDK per PHP
-
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
use Aws\Sns\SnsClient;
/**
* Deletes an SNS topic and all its subscriptions.
*
* This code expects that you have AWS credentials set up per:
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
*/
$SnSclient = new SnsClient([
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2010-03-31'
]);
$topic = 'arn:aws:sns:us-east-1:111122223333:MyTopic';
try {
$result = $SnSclient->deleteTopic([
'TopicArn' => $topic,
]);
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
error_log($e->getMessage());
}
- Python
-
- SDKper Python (Boto3)
-
class SnsWrapper:
"""Encapsulates Amazon SNS topic and subscription functions."""
def __init__(self, sns_resource):
"""
:param sns_resource: A Boto3 Amazon SNS resource.
"""
self.sns_resource = sns_resource
@staticmethod
def delete_topic(topic):
"""
Deletes a topic. All subscriptions to the topic are also deleted.
"""
try:
topic.delete()
logger.info("Deleted topic %s.", topic.arn)
except ClientError:
logger.exception("Couldn't delete topic %s.", topic.arn)
raise
- SAP ABAP
-
- SDKper SAP ABAP
-
TRY.
lo_sns->deletetopic( iv_topicarn = iv_topic_arn ).
MESSAGE 'SNS topic deleted.' TYPE 'I'.
CATCH /aws1/cx_snsnotfoundexception.
MESSAGE 'Topic does not exist.' TYPE 'E'.
ENDTRY.