Gunakan CreateContactList dengan AWS SDK atau CLI - AWS SDKContoh Kode

Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan CreateContactList dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanCreateContactList.

Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:

.NET
AWS SDK for .NET
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

/// <summary> /// Creates a contact list with the specified name. /// </summary> /// <param name="contactListName">The name of the contact list.</param> /// <returns>True if successful.</returns> public async Task<bool> CreateContactListAsync(string contactListName) { var request = new CreateContactListRequest { ContactListName = contactListName }; try { var response = await _sesClient.CreateContactListAsync(request); return response.HttpStatusCode == HttpStatusCode.OK; } catch (AlreadyExistsException ex) { Console.WriteLine($"Contact list with name {contactListName} already exists."); Console.WriteLine(ex.Message); return true; } catch (LimitExceededException ex) { Console.WriteLine("The limit for contact lists has been exceeded."); Console.WriteLine(ex.Message); } catch (TooManyRequestsException ex) { Console.WriteLine("Too many requests were made. Please try again later."); Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine($"An error occurred while creating the contact list: {ex.Message}"); } return false; }
Java
SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

try { // 2. Create a contact list String contactListName = CONTACT_LIST_NAME; CreateContactListRequest createContactListRequest = CreateContactListRequest.builder() .contactListName(contactListName) .build(); sesClient.createContactList(createContactListRequest); System.out.println("Contact list created: " + contactListName); } catch (AlreadyExistsException e) { System.out.println("Contact list already exists, skipping creation: weekly-coupons-newsletter"); } catch (LimitExceededException e) { System.err.println("Limit for contact lists has been exceeded."); throw e; } catch (SesV2Exception e) { System.err.println("Error creating contact list: " + e.getMessage()); throw e; }
Python
SDKuntuk Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

def main(): """ The main function that orchestrates the execution of the workflow. """ print(INTRO) ses_client = boto3.client("sesv2") workflow = SESv2Workflow(ses_client) try: workflow.prepare_application() workflow.gather_subscriber_email_addresses() workflow.send_coupon_newsletter() workflow.monitor_and_review() except ClientError as e: print_error(e) workflow.clean_up() class SESv2Workflow: """ A class to manage the SES v2 Coupon Newsletter Workflow. """ def __init__(self, ses_client, sleep=True): self.ses_client = ses_client self.sleep = sleep try: self.ses_client.create_contact_list(ContactListName=CONTACT_LIST_NAME) print(f"Contact list '{CONTACT_LIST_NAME}' created successfully.") except ClientError as e: # If the contact list already exists, skip and proceed if e.response["Error"]["Code"] == "AlreadyExistsException": print(f"Contact list '{CONTACT_LIST_NAME}' already exists.") else: raise e
Rust
SDKuntuk Rust
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

async fn make_list(client: &Client, contact_list: &str) -> Result<(), Error> { client .create_contact_list() .contact_list_name(contact_list) .send() .await?; println!("Created contact list."); Ok(()) }