Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Example of sending a media message in AWS End User Messaging Social

Focus mode
Example of sending a media message in AWS End User Messaging Social - AWS End User Messaging Social

The following example shows how to send a media message to your customer using the AWS CLI. For more information on configuring the AWS CLI, see Configure the AWS CLI in the AWS Command Line Interface User Guide. For a list of supported media file types, see Supported media file types and sizes in WhatsApp.

Note

WhatsApp stores media files for 30 days before deleting them, see Upload Media in the WhatsApp Business Platform Cloud API Reference.

  1. Upload the media file to an Amazon S3 bucket. For more information, see Uploading media files to send with WhatsApp.

  2. Upload the media file to WhatsApp using the post-whatsapp-message-media command. On successful completion, the command will return the {MEDIA_ID}, which is required for sending the media message.

    aws socialmessaging post-whatsapp-message-media --origination-phone-number-id {ORIGINATION_PHONE_NUMBER_ID} --source-s3-file bucketName={BUCKET},key={MEDIA_FILE}

    In the preceding command, do the following:

    • Replace {ORIGINATION_PHONE_NUMBER_ID} with your phone number's ID.

    • Replace {BUCKET} with the name of the Amazon S3 bucket.

    • Replace {MEDIA_FILE} with the name of the media file.

    You can also upload using a presign url by using --source-s3-presigned-url instead of --source-s3-file. You must add Content-Type in the headers field. If you use both then an InvalidParameterException is returned.

    --source-s3-presigned-url headers={"Name":"Value"},url=https://BUCKET.s3.REGION/MEDIA_FILE
  3. Use the send-whatsapp-message command to send the media message.

    aws socialmessaging send-whatsapp-message --message '{"messaging_product":"whatsapp","to":"'{PHONE_NUMBER}'","type":"image","image":{"id":"'{MEDIA_ID}'"}}' --origination-phone-number-id {ORIGINATION_PHONE_NUMBER_ID} --meta-api-version v20.0
    Note

    You must specify base64 encoding when you use the AWS CLI version 2. This can be done by adding the AWS CLI paramater --cli-binary-format raw-in-base64-out or changing the AWS CLI global configuration file. For more information, see cli_binary_format in the AWS Command Line Interface User Guide for Version 2.

    aws socialmessaging send-whatsapp-message --message '{"messaging_product":"whatsapp","to":"'{PHONE_NUMBER}'","type":"image","image":{"id":"'{MEDIA_ID}'"}}' --origination-phone-number-id {ORIGINATION_PHONE_NUMBER_ID} --meta-api-version v20.0 --cli-binary-format raw-in-base64-out

    In the preceding command, do the following:

    • Replace {PHONE_NUMBER} with your customer's phone number.

    • Replace {ORIGINATION_PHONE_NUMBER_ID} with your phone number's ID.

    • Replace {MEDIA_ID} with the media ID returned from the previous step.

  4. When you no longer need the media file, you can delete it from WhatsApp using the delete-whatsapp-message-media command. This only removes the media file from WhatsApp and not your Amazon S3 bucket.

    aws socialmessaging delete-whatsapp-message-media --media-id {MEDIA_ID} --origination-phone-number-id {ORIGINATION_PHONE_NUMBER_ID}

    In the preceding command, do the following:

    • Replace {ORIGINATION_PHONE_NUMBER_ID} with your phone number's ID.

    • Replace {MEDIA_ID} with the media ID.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.