Use GetSMSAttributes
with an AWS SDK or CLI
The following code examples show how to use GetSMSAttributes
.
- C++
-
- SDK for C++
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. //! 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(); }
-
For API details, see GetSMSAttributes in AWS SDK for C++ API Reference.
-
- CLI
-
- AWS CLI
-
To list the default SMS message attributes
The following
get-sms-attributes
example lists the default attributes for sending SMS messages.aws sns get-sms-attributes
Output:
{ "attributes": { "DefaultSenderID": "MyName" } }
-
For API details, see GetSMSAttributes
in AWS CLI Command Reference.
-
- Java
-
- SDK for Java 2.x
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. 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"); } }
-
For API details, see GetSMSAttributes in AWS SDK for Java 2.x API Reference.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Create the client in a separate module and export it.
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({});
Import the SDK and client modules and call the API.
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; };
-
For more information, see AWS SDK for JavaScript Developer Guide.
-
For API details, see GetSMSAttributes in AWS SDK for JavaScript API Reference.
-
- PHP
-
- SDK for PHP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. 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()); }
-
For more information, see AWS SDK for PHP Developer Guide.
-
For API details, see GetSMSAttributes in AWS SDK for PHP API Reference.
-
For a complete list of AWS SDK developer guides and code examples, see Using Amazon SNS with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.