GetSMSAttributesÚselo con un AWS SDK o CLI - Ejemplos de código de AWS SDK

Hay más AWS SDK ejemplos disponibles en el GitHub repositorio de AWS Doc SDK Examples.

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

GetSMSAttributesÚselo con un AWS SDK o CLI

En los siguientes ejemplos de código, se muestra cómo utilizar GetSMSAttributes.

C++
SDKpara C++
nota

Hay más información GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

//! Retrieve the default settings for sending SMS messages from your AWS account by using //! Amazon Simple Notification Service (Amazon SNS). /*! \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SNS::getSMSType(const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SNS::SNSClient snsClient(clientConfiguration); Aws::SNS::Model::GetSMSAttributesRequest request; //Set the request to only retrieve the DefaultSMSType setting. //Without the following line, GetSMSAttributes would retrieve all settings. request.AddAttributes("DefaultSMSType"); const Aws::SNS::Model::GetSMSAttributesOutcome outcome = snsClient.GetSMSAttributes( request); if (outcome.IsSuccess()) { const Aws::Map<Aws::String, Aws::String> attributes = outcome.GetResult().GetAttributes(); if (!attributes.empty()) { for (auto const &att: attributes) { std::cout << att.first << ": " << att.second << std::endl; } } else { std::cout << "AwsDoc::SNS::getSMSType - an empty map of attributes was retrieved." << std::endl; } } else { std::cerr << "Error while getting SMS Type: '" << outcome.GetError().GetMessage() << "'" << std::endl; } return outcome.IsSuccess(); }
  • Para API obtener más información, consulte G etSMSAttributes en la AWS SDK for C++ APIreferencia.

CLI
AWS CLI

Para enumerar los atributos predeterminados de los SMS mensajes

En el siguiente get-sms-attributes ejemplo, se enumeran los atributos predeterminados para el envío de SMS mensajes.

aws sns get-sms-attributes

Salida:

{ "attributes": { "DefaultSenderID": "MyName" } }
  • Para API obtener más información, consulte G etSMSAttributes en la Referencia de AWS CLI comandos.

Java
SDKpara Java 2.x
nota

Hay más información. GitHub Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.sns.SnsClient; import software.amazon.awssdk.services.sns.model.GetSubscriptionAttributesRequest; import software.amazon.awssdk.services.sns.model.GetSubscriptionAttributesResponse; import software.amazon.awssdk.services.sns.model.SnsException; import java.util.Iterator; import java.util.Map; /** * 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 GetSMSAtrributes { public static void main(String[] args) { final String usage = """ Usage: <topicArn> Where: topicArn - The ARN of the topic from which to retrieve attributes. """; 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(); getSNSAttrutes(snsClient, topicArn); snsClient.close(); } public static void getSNSAttrutes(SnsClient snsClient, String topicArn) { try { GetSubscriptionAttributesRequest request = GetSubscriptionAttributesRequest.builder() .subscriptionArn(topicArn) .build(); // Get the Subscription attributes GetSubscriptionAttributesResponse res = snsClient.getSubscriptionAttributes(request); Map<String, String> map = res.attributes(); // Iterate through the map Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); System.out.println("[Key] : " + entry.getKey() + " [Value] : " + entry.getValue()); } } catch (SnsException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } System.out.println("\n\nStatus was good"); } }
  • Para API obtener más información, consulte G etSMSAttributes en la AWS SDK for Java 2.x APIreferencia.

JavaScript
SDKpara JavaScript (v3)
nota

Hay más información. GitHub Busque el ejemplo completo y aprenda a configurarlo y ejecutarlo en el Repositorio de ejemplos de código de AWS.

Cree el cliente en un módulo separado y expórtelo.

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({});

Importe los módulos SDK y del cliente y llame alAPI.

import { GetSMSAttributesCommand } from "@aws-sdk/client-sns"; import { snsClient } from "../libs/snsClient.js"; export const getSmsAttributes = async () => { const response = await snsClient.send( // If you have not modified the account-level mobile settings of SNS, // the DefaultSMSType is undefined. For this example, it was set to // Transactional. new GetSMSAttributesCommand({ attributes: ["DefaultSMSType"] }), ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '67ad8386-4169-58f1-bdb9-debd281d48d5', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // attributes: { DefaultSMSType: 'Transactional' } // } return response; };
PHP
SDK para PHP
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

require 'vendor/autoload.php'; use Aws\Exception\AwsException; use Aws\Sns\SnsClient; /** * Get the type of SMS Message sent by default from the AWS SNS service. * * 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' ]); try { $result = $SnSclient->getSMSAttributes([ 'attributes' => ['DefaultSMSType'], ]); var_dump($result); } catch (AwsException $e) { // output error message if fails error_log($e->getMessage()); }