0

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

我查看了AWS Organizations SDK 文档,尤其是在create-account方面,但没有发现任何相关内容。

4

2 回答 2

0

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

在组织 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)
于 2020-05-12T12:54:50.877 回答
0

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

下面是我用python编写的取消订阅函数。
注意:我喜欢@samtoddler 的示例,它使用漂亮的汤来动态查找formid vs 硬编码它作为函数输入变量,就像我拥有的​​一样。

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)
于 2022-02-23T17:36:49.440 回答