Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Error ao enviar a notificação

Response { "errorMessage": "An error occurred (AuthorizationError) when calling the Publish operation: User: arn:aws:sts::240006421420:assumed-role/testaSite-role-b2tbu2jg/testaSite is not authorized to perform: SNS:Publish on resource: arn:aws:sns:us-east-1:240006421420:Default_Gmail", "errorType": "AuthorizationErrorException", "stackTrace": [ [ "/var/task/lambda_function.py", 16, "lambda_handler", "envia_notificacao()" ], [ "/var/task/lambda_function.py", 22, "envia_notificacao", "Subject='ALERTA')" ], [ "/var/runtime/botocore/client.py", 357, "apicall", "return self.makeapi_call(operation_name, kwargs)" ], [ "/var/runtime/botocore/client.py", 676, "makeapi_call", "raise error_class(parsed_response, operation_name)" ] ] }

Function Logs START RequestId: 3e008807-f315-4bb8-a2c0-17728e7eb963 Version: $LATEST /var/runtime/botocore/vendored/requests/api.py:72: DeprecationWarning: You are using the get() function from 'botocore.vendored.requests'. This dependency was removed from Botocore and will be removed from Lambda after 2021-12-01. https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/. Install the requests package, 'import requests' directly, and use the requests.get() function instead. DeprecationWarning Houston, we have a problem! An error occurred (AuthorizationError) when calling the Publish operation: User: arn:aws:sts::240006421420:assumed-role/testaSite-role-b2tbu2jg/testaSite is not authorized to perform: SNS:Publish on resource: arn:aws:sns:us-east-1:240006421420:Default_Gmail: AuthorizationErrorException Traceback (most recent call last): File "/var/task/lambda_function.py", line 16, in lambda_handler envia_notificacao() File "/var/task/lambda_function.py", line 22, in envia_notificacao Subject='ALERTA') File "/var/runtime/botocore/client.py", line 357, in apicall return self.makeapi_call(operation_name, kwargs) File "/var/runtime/botocore/client.py", line 676, in makeapi_call raise error_class(parsed_response, operation_name) botocore.errorfactory.AuthorizationErrorException: An error occurred (AuthorizationError) when calling the Publish operation: User: arn:aws:sts::240006421420:assumed-role/testaSite-role-b2tbu2jg/testaSite is not authorized to perform: SNS:Publish on resource: arn:aws:sns:us-east-1:240006421420:Default_Gmail

END RequestId: 3e008807-f315-4bb8-a2c0-17728e7eb963 REPORT RequestId: 3e008807-f315-4bb8-a2c0-17728e7eb963 Duration: 209.75 ms Billed Duration: 210 ms Memory Size: 128 MB Max Memory Used: 72 MB

Request ID 3e008807-f315-4bb8-a2c0-17728e7eb963

3 respostas

segue o código.:

from botocore.vendored import requests import boto3

client = boto3.client('sns')

site = 'http://ec2-34-201-68-123.compute-1.amazonaws.com' web_hook = 'URL WEB_HOOK' mensagem = {'text': '=====Houston, we have a problem!====='}

def lambda_handler(event, context): try: requests.get(site, timeout=5) print('Site OK!') except Exception: print('Houston, we have a problem!')

    #envia_notificacao()

def envia_notificacao(): client.publish( TopicArn='arn:aws:sns:us-east-1:240006421420:Default_Gmail', Message='Houston, we have a problem!', Subject='ALERTA')

Se eu comentar a função envia_notificacao() funciona normalmente

solução!

resolvido!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software