Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何为CustomMessage\u AdminCreateUser触发器发送自定义消息?_Python_Amazon Web Services_Amazon Cognito_Amazon Cognito Triggers - Fatal编程技术网

Python 如何为CustomMessage\u AdminCreateUser触发器发送自定义消息?

Python 如何为CustomMessage\u AdminCreateUser触发器发送自定义消息?,python,amazon-web-services,amazon-cognito,amazon-cognito-triggers,Python,Amazon Web Services,Amazon Cognito,Amazon Cognito Triggers,在为CustomMessage\u AdminCreateUser触发器发送自定义电子邮件时,我成功地更改了从Amazon Cognito收到的事件中的emailSubject属性,但似乎无法更改emailMessage属性 从Cognito发送的电子邮件包含正确的自定义主题,但消息根本不是自定义的,它始终是在Cognito池设置中设置的主题 处理从Cognito接收的事件的lambda处理程序成功地定制了这些触发器的消息: CustomMessage\u注册 CustomMessage\u

在为
CustomMessage\u AdminCreateUser
触发器发送自定义电子邮件时,我成功地更改了从Amazon Cognito收到的事件中的
emailSubject
属性,但似乎无法更改
emailMessage
属性

从Cognito发送的电子邮件包含正确的自定义主题,但消息根本不是自定义的,它始终是在Cognito池设置中设置的主题

处理从Cognito接收的事件的lambda处理程序成功地定制了这些触发器的消息:

  • CustomMessage\u注册
  • CustomMessage\u ResendCode
  • CustomMessage\u放弃密码
但是对于
CustomMessage\u AdminCreateUser
trigger,我似乎无法让它工作(至少不能完全工作)

我尝试将
email\u verified
user属性设置为
true
,以查看该属性是否取决于是否成功地将自定义邮件发送给创建的用户。此外,我尝试在Docker容器中运行lambda,以查看返回到Cognito的最终事件的输出,但是该事件包含正确的数据,电子邮件主题和电子邮件消息都是定制的

def lambda_处理程序(事件、上下文):
如果事件['userPoolId']==os.getenv('cognitoPoolId'):
如果CustomMessageTriggerNum.has_值(event.get('triggerSource')):
custom\u message\u trigger=CustomMessageTriggerEnum(event.get('triggerSource'))
如果custom_message_trigger==CustomMessageTriggerEnum.CustomMessageAdminCreateUser:
自定义\消息\触发器=CustomMessageAdminCreateUser(事件)
其他:
一无所获
自定义\响应=自定义\消息\触发器。获取\自定义\响应(
自定义消息触发动作,
自定义消息触发电子邮件主题,
自定义\u消息\u触发器。电子邮件\u消息
)
事件=自定义消息触发。设置自定义响应(**自定义响应)
返回事件
类CustomMessageAdminCreateUser(BaseCustomMessageTrigger):
“”“自定义邮件管理员创建用户触发器”“”
ACTION=“changepassword”
电子邮件_SUBJECT=“欢迎使用{service}”
EMAIL_MESSAGE=“您的帐户已创建。请设置密码并开始使用{service}。”
定义初始化(自我,事件):
超级()。\uuuu初始化\uuuu(事件)
class BaseCustomMessageTrigger():
“”“基本自定义消息触发器”“”
定义初始化(自我,事件):
self.event=事件
def获取自定义响应(自我、操作、电子邮件主题、电子邮件消息):
“”“将自定义响应参数作为字典获取”“”
request=self.event.get('request')
自定义_响应={}
url=self.get\u url(
行动,
code=request.get('code参数'),
email=urlencode({'email':请求['userAttributes'].get('email')})
)
自定义_响应['emailSubject']=电子邮件_主题
自定义_响应['emailMessage']=电子邮件_message.format(url)
返回自定义\u响应
def set_自定义_响应(自身,**kwargs):
“”“使用提供的KWARG更新事件响应”“”
response=self.event.get('response')
回复。更新(**kwargs)
返回自我事件
def get_url(自我、操作、代码、电子邮件):
“”“用于构造URL。”“”
rawUrl='https://{0}/{1}?代码={2}&{3}'
返回rawUrl.format(域、操作、代码、电子邮件)

对于
CustomMessage\u AdminCreateUser
触发器,一个重要的事情是您必须在mail
emailMessage
中包含
用户名
密码

def get_url(self, action, code, email):
        """ Used for constructing URLs. """
        rawUrl = 'https://{0}/{1}?code={2}&{3}'
        return rawUrl.format(domain, action, code, email)

请通过
get\u url
方法传递
domain

对于
CustomMessage\u AdminCreateUser
触发器,一个重要的事情是您必须在mail
emailMessage
中包含
username
password

def get_url(self, action, code, email):
        """ Used for constructing URLs. """
        rawUrl = 'https://{0}/{1}?code={2}&{3}'
        return rawUrl.format(domain, action, code, email)

请在
get\u url
方法中传递
domain

您必须避免在响应参数上使用urlencode,因为Lambda将添加占位符,这些占位符稍后将被Cognito替换。

您必须避免在响应参数上使用urlencode,因为Lambda将添加占位符,这些占位符稍后将被Cognito替换。

I有完全相同的问题

我的初始自定义消息:

<html>
    <body>
      <p> Welcome. Follow the link below to unlock your account and set a new password.</p>
      <a href="http://localhost:3000/setNewPasswordcode_parameter=${event.request.codeParameter}&user_name=${event.userName}">Set Password</a>
    </body>
</html>

对于链接,您可以使用
event.userName
——这应该是cognito用户的子项。只需确保在电子邮件中的其他地方包含
event.request.usernameparter
。在我的例子中,我用
Welcome,${event.request.usernameparmeter}启动邮件

我遇到了完全相同的问题

我的初始自定义消息:

<html>
    <body>
      <p> Welcome. Follow the link below to unlock your account and set a new password.</p>
      <a href="http://localhost:3000/setNewPasswordcode_parameter=${event.request.codeParameter}&user_name=${event.userName}">Set Password</a>
    </body>
</html>

对于链接,您可以使用
event.userName
——这应该是cognito用户的子项。只需确保在电子邮件中的其他地方包含
event.request.usernameparter
。在我的例子中,我用
Welcome,${event.request.usernameparmeter}启动邮件

只是为了澄清电子邮件应该包含
event.request.usernameparmeter
event.request.codeparmeter
中的值


我发现Cognito忽略了我的电子邮件正文,因为标记
{username}
丢失了,即使
{code}{code}
在那里。

只是为了澄清电子邮件应该包含
event.request.usernameparter
event.request.codeparter
中的值


我发现Cognito忽略了我的电子邮件正文,因为标记
{username}
丢失了,即使
{code}{code}
在那里。

URL中包含了
用户名
密码
作为查询参数,我可以从传递到lambda处理程序的Cognito事件中访问这些字段,并使用它们格式化ema