【问题标题】:SDK to unsubscribe from marketing emails in AWS Organizations member accounts用于取消订阅 AWS Organizations 成员账户中的营销电子邮件的 SDK
【发布时间】:2019-06-11 10:34:20
【问题描述】:

我有一个 AWS 组织,并为我创建的每个新项目创建成员账户。由于我可以控制所有帐户,因此我对所有这些帐户使用相同的电子邮件帐户,使用 account-name+project-name@gmail.com 模式。 这意味着我为我创建的每个新帐户都会收到相同的营销电子邮件。我知道我可以手动取消订阅,但由于我是通过 CLI 创建成员帐户的,所以我想知道是否有办法通过 SDK 自动取消订阅(或避免被订阅)。

我查看了AWS Organizations SDK documentation,尤其是create-account,但没有发现任何相关信息。

【问题讨论】:

    标签: amazon-web-services aws-sdk aws-cli aws-organizations


    【解决方案1】:

    显然 AWS 对此没有解决方案。我找到的唯一地方是this。其中涉及人工干预。

    在组织 ID 上执行此操作是一个不错的选择。

    同时,我写了这个作为解决方法。

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import requests
    from bs4 import BeautifulSoup
    GET_URL = 'https://pages.awscloud.com/communication-preferences'
    POST_URL = 'https://pages.awscloud.com/index.php/leadCapture/save2'
    s = requests.Session()
    def fetch(url, data=None):
        if data is None:
            return s.get(url).content
        return s.post(url, data=data).content
    def get_form_id():
        forms = BeautifulSoup(fetch(GET_URL), 'html.parser').findAll('form')
        for form in forms:
            fields = form.findAll('input')
            for field in fields:
                if field.get('name') == 'formid':
                    return field['value']
    email_id = 'testing@example.com'
    formid = get_form_id()
    form_data = {'Email': email_id, 'Unsubscribed': 'yes', 'formid': formid, 'formVid': formid}
    r = fetch(POST_URL, data=form_data)
    print(r)
    

    【讨论】:

      【解决方案2】:

      AWS 最近再次更改了此 Web 表单,破坏了我编写的现有取消订阅功能。他们添加了 2 个新的必填表单数据字段:checksumchecksumFieldschecksum 字段是所有 checksumFields 值(与 , 连接的单个字符串)串联的 sha256 哈希。

      下面是我用 python 编写的取消订阅函数。
      注意:我喜欢 @samtoddler 的示例,它使用美丽的汤来动态查找 formid 与将其硬编码为函数输入 var,就像我一样有。

      def unsubscribe_aws_mkt_emails(email,
                                     url='https://pages.awscloud.com/index.php/leadCapture/save2',
                                     form_id=34006,
                                     lp_id=127906,
                                     sub_id=6,
                                     munchkin_id='112-TZM-766'):
          '''
          Unsubscribes email from AWS marketing emails via HTTPS POST
          '''
          sha256_hash = hashlib.sha256()
      
          # Data fields used to calculate the payload SHA256 checksum value
          checksum_fields = [
              'FirstName',
              'LastName',
              'Email',
              'Company',
              'Phone',
              'Country',
              'preferenceCenterCategory',
              'preferenceCenterGettingStarted',
              'preferenceCenterOnlineInPersonEvents',
              'preferenceCenterMonthlyAWSNewsletter',
              'preferenceCenterTrainingandBestPracticeContent',
              'preferenceCenterProductandServiceAnnoucements',
              'preferenceCenterSurveys',
              'PreferenceCenter_AWS_Partner_Events_Co__c',
              'preferenceCenterOtherAWSCommunications',
              'PreferenceCenter_Language_Preference__c',
              'Title',
              'Job_Role__c',
              'Industry',
              'Level_of_AWS_Usage__c',
          ]
      
          headers = {
              'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
              'user-agent': 'Mozilla/5.0',
          }
      
          data_dict = {
              'Email': email,
              'preferenceCenterCategory': 'no',
              'preferenceCenterGettingStarted': 'no',
              'preferenceCenterOnlineInPersonEvents': 'no',
              'preferenceCenterMonthlyAWSNewsletter': 'no',
              'preferenceCenterTrainingandBestPracticeContent': 'no',
              'preferenceCenterProductandServiceAnnoucements': 'no',
              'preferenceCenterSurveys': 'no',
              'PreferenceCenter_AWS_Partner_Events_Co__c': 'no',
              'preferenceCenterOtherAWSCommunications': 'no',
              'Unsubscribed': 'yes',
              'UnsubscribedReason': 'I already get email from another account',
              'unsubscribedReasonOther': 'I already get email from another account',
              'zOPEmailValidationHygiene': 'validate',
              'formid': form_id,
              'formVid': form_id,
              'lpId': lp_id,
              'subId': sub_id,
              'munchkinId': munchkin_id,
              'lpurl': '//pages.awscloud.com/communication-preferences.html?cr={creative}&kw={keyword}',
              '_mkt_trk': f'id:{munchkin_id}&token:_mch-pages.awscloud.com-1644428507420-99548',
              '_mktoReferrer': 'https://pages.awscloud.com/communication-preferences',
              'checksumFields': ','.join(checksum_fields),
          }
      
          # calculated via js: f.checksum=v("sha256").update(s.join("|")).digest("hex")
          # src = https://pages.awscloud.com/js/forms2/js/forms2.min.js
          sha256_hash.update('|'.join([data_dict.get(v, '') for v in checksum_fields]).encode())
          data_dict['checksum'] = sha256_hash.hexdigest()
          data = parse.urlencode(data_dict).encode()
          req = request.Request(url, data=data, headers=headers, method='POST')
          resp = request.urlopen(req)
      

      【讨论】:

        猜你喜欢
        • 2012-12-02
        • 1970-01-01
        • 1970-01-01
        • 2011-10-10
        • 1970-01-01
        • 1970-01-01
        • 2011-03-24
        • 1970-01-01
        • 2023-01-29
        相关资源
        最近更新 更多