简体   繁体   English

AWS Batch Job 应用程序无法发送 SNS 通知

[英]AWS Batch Job application not being able to send SNS notification

I have an AWS Batch Job which is a .NET CORE app running as a container which downloads from an SFTP server a CSV parses it and inserts data into AWS RDS.我有一个 AWS Batch Job,它是一个 .NET CORE 应用程序,作为一个容器运行,它从 SFTP 服务器下载一个 CSV 解析它并将数据插入 AWS RDS。

When the CSV is corrupt the job is failing and is supposed to send a SNS notification, instead I see the following error in CloudWatch logs.当 CSV 损坏时,作业失败并且应该发送 SNS 通知,但我在 CloudWatch 日志中看到以下错误。

 "Message": "User: arn:aws:sts::654001826221:assumed-role/fileimportworker-batch/5f77c736e4e64c2d82df278800ec4f25 is not authorized to perform: SNS:Publish on resource: arn:aws:sns:eu-west-1:accountIdHere:Test-SNS-Batch",

My IAM role attached to the batch Job role has SNS:Published allowed, S3 allowed, also provides read access to 2 secrets in Secret Manager.附加到批处理作业角色的我的 IAM 角色允许 SNS:发布,允许 S3,还提供对秘密管理器中 2 个秘密的读取访问权限。 S3 and SecretManager access work, the task is able to download the file from SFTP and put it to S3 and also to read the RDS password from secret manager. S3 和 SecretManager 访问工作,该任务能够从 SFTP 下载文件并将其放入 S3,还可以从 Secret Manager 读取 RDS 密码。

AWS Batch Job may use credentials from a container instead of your environment variables. AWS Batch Job 可能会使用来自容器的凭证而不是您的环境变量。 You have to look at credential precedence.您必须查看凭证优先级。

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-precedence https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-precedence

The AWS CLI uses credentials and configuration settings located in multiple places, such as the system or user environment variables, local AWS configuration files, or explicitly declared on the command line as a parameter. AWS CLI 使用位于多个位置的凭证和配置设置,例如系统或用户环境变量、本地 AWS 配置文件,或在命令行上明确声明为参数。 Certain locations take precedence over others.某些位置优先于其他位置。 The AWS CLI credentials and configuration settings take precedence in the following order: AWS CLI 凭证和配置设置按以下顺序优先:

  1. Command line options – Overrides settings in any other location.命令行选项 - 覆盖任何其他位置的设置。 You can specify --region, --output, and --profile as parameters on the command line.您可以在命令行上指定 --region、--output 和 --profile 作为参数。

  2. Environment variables – You can store values in your system's environment variables.环境变量 – 您可以将值存储在系统的环境变量中。

  3. CLI credentials file – The credentials and config file are updated when you run the command aws configure. CLI 凭证文件 – 当您运行命令 aws configure 时,凭证和配置文件会更新。 The credentials file is located at ~/.aws/credentials on Linux or macOS, or at C:\Users\USERNAME.aws\credentials on Windows. This file can contain the credential details for the default profile and any named profiles.凭证文件位于 Linux 或 macOS 上的 ~/.aws/credentials,或 Windows 上的 C:\Users\USERNAME.aws\credentials。此文件可以包含默认配置文件和任何命名配置文件的凭证详细信息。

  4. CLI configuration file – The credentials and config file are updated when you run the command aws configure. CLI 配置文件 – 凭证和配置文件在您运行命令 aws configure 时更新。 The config file is located at ~/.aws/config on Linux or macOS, or at C:\Users\USERNAME.aws\config on Windows. This file contains the configuration settings for the default profile and any named profiles.配置文件位于 Linux 或 macOS 上的 ~/.aws/config,或 Windows 上的 C:\Users\USERNAME.aws\config。此文件包含默认配置文件和任何命名配置文件的配置设置。

  5. Container credentials – You can associate an IAM role with each of your Amazon Elastic Container Service (Amazon ECS) task definitions.容器凭证 – 您可以将 IAM 角色与每个 Amazon Elastic Container Service (Amazon ECS) 任务定义相关联。 Temporary credentials for that role are then available to that task's containers.该角色的临时凭证随后可用于该任务的容器。 For more information, see IAM Roles for Tasks in the Amazon Elastic Container Service Developer Guide.有关更多信息,请参阅 Amazon Elastic Container Service 开发人员指南中的任务的 IAM 角色。

  6. Instance profile credentials – You can associate an IAM role with each of your Amazon Elastic Compute Cloud (Amazon EC2) instances.实例配置文件凭证 – 您可以将 IAM 角色与每个 Amazon Elastic Compute Cloud (Amazon EC2) 实例相关联。 Temporary credentials for that role are then available to code running in the instance.该角色的临时凭证随后可用于实例中运行的代码。 The credentials are delivered through the Amazon EC2 metadata service.凭据通过 Amazon EC2 元数据服务提供。 For more information, see IAM Roles for Amazon EC2 in the Amazon EC2 User Guide for Linux Instances and Using Instance Profiles in the IAM User Guide.有关更多信息,请参阅 Linux 实例的 Amazon EC2 用户指南中的 Amazon EC2 的 IAM 角色和 IAM 用户指南中的使用实例配置文件。

PS To intergate AWS Batch with SNS without coding, you can use the Eventbridge rule to listen to event patterns from AWS Batch. PS 要在不编码的情况下将 AWS Batch 与 SNS 集成,您可以使用 Eventbridge 规则来侦听来自 AWS Batch 的事件模式。 You just select the target of the rule to publish the message on the SNS topic you want.您只需 select 规则的目标即可在您想要的 SNS 主题上发布消息。

https://docs.aws.amazon.com/batch/latest/userguide/batch_sns_tutorial.html https://docs.aws.amazon.com/batch/latest/userguide/batch_sns_tutorial.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM