または GetTemplate で を使用する AWS SDK CLI - AWS SDK コード例

AWS Doc SDK Examples GitHub リポジトリには他にも AWS SDK例があります。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

または GetTemplate で を使用する AWS SDK CLI

以下のコード例は、GetTemplate の使用方法を示しています。

アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。

C++
SDK C++ 用
注記

については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

//! Get a template's attributes. /*! \param templateName: The name for the template. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SES::getTemplate(const Aws::String &templateName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SES::SESClient sesClient(clientConfiguration); Aws::SES::Model::GetTemplateRequest getTemplateRequest; getTemplateRequest.SetTemplateName(templateName); Aws::SES::Model::GetTemplateOutcome outcome = sesClient.GetTemplate( getTemplateRequest); if (outcome.IsSuccess()) { std::cout << "Successfully got template." << std::endl; } else { std::cerr << "Error getting template. " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • API 詳細については、「 リファレンスGetTemplate」の「」を参照してください。 AWS SDK for C++ API

JavaScript
SDK の JavaScript (v3)
注記

については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

import { GetTemplateCommand } from "@aws-sdk/client-ses"; import { getUniqueName } from "@aws-doc-sdk-examples/lib/utils/util-string.js"; import { sesClient } from "./libs/sesClient.js"; const TEMPLATE_NAME = getUniqueName("TemplateName"); const createGetTemplateCommand = (templateName) => new GetTemplateCommand({ TemplateName: templateName }); const run = async () => { const getTemplateCommand = createGetTemplateCommand(TEMPLATE_NAME); try { return await sesClient.send(getTemplateCommand); } catch (caught) { if (caught instanceof Error && caught.name === "MessageRejected") { /** @type { import('@aws-sdk/client-ses').MessageRejected} */ const messageRejectedError = caught; return messageRejectedError; } throw caught; } };
  • API 詳細については、「 リファレンスGetTemplate」の「」を参照してください。 AWS SDK for JavaScript API

Python
SDK for Python (Boto3)
注記

については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

class SesTemplate: """Encapsulates Amazon SES template functions.""" def __init__(self, ses_client): """ :param ses_client: A Boto3 Amazon SES client. """ self.ses_client = ses_client self.template = None self.template_tags = set() def _extract_tags(self, subject, text, html): """ Extracts tags from a template as a set of unique values. :param subject: The subject of the email. :param text: The text version of the email. :param html: The html version of the email. """ self.template_tags = set(re.findall(TEMPLATE_REGEX, subject + text + html)) logger.info("Extracted template tags: %s", self.template_tags) def get_template(self, name): """ Gets a previously created email template. :param name: The name of the template to retrieve. :return: The retrieved email template. """ try: response = self.ses_client.get_template(TemplateName=name) self.template = response["Template"] logger.info("Got template %s.", name) self._extract_tags( self.template["SubjectPart"], self.template["TextPart"], self.template["HtmlPart"], ) except ClientError: logger.exception("Couldn't get template %s.", name) raise else: return self.template
  • API 詳細については、GetTemplate「 for AWS SDK Python (Boto3) APIリファレンス」の「」を参照してください。