简体   繁体   English

如何使用 CLOUDFORMATION 将我的 aws 帐户中的现有角色附加到 aws 组件/Lambda 函数

[英]How to attach an EXISTING Role in my aws account to aws componennt/Lambda Funtion using CLOUDFORMATION

Hi AWS Cloudformation guys!嗨 AWS Cloudformation 伙计们!

I need to attach an existing role to the lambda function i am creating.我需要将现有角色附加到我正在创建的 lambda function。

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
  LambdaRoleName:
    Default: ExistingRoleCreatedInAwsAccount
    Type: String
Resources:
  LambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      Runtime: python3.9
      Timeout: 5
      Handler: lambda_function.handler
      Role: !Ref ExistingRoleCreatedInAwsAccount
      Code:
        S3Bucket: 'lambda-bucket-abi'
        S3Key: 'lambdaupload.zip'

  ScheduledRule:
    Type: AWS::Events::Rule
    Properties:
      Description: "ScheduledRule"
      ScheduleExpression: "rate(5 minutes)"
      State: "ENABLED"
      Targets:
        - Arn:
            Fn::GetAtt:
              - "LambdaFunction"
              - "Arn"
          Id: "TargetFunctionV1"
  PermissionForEventsToInvokeLambda:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !Ref "LambdaFunction"
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn:
        Fn::GetAtt:
          - "ScheduledRule"
          - "Arn"

Thanks in Advance!提前致谢!

You seem to be on the right track, what's going wrong?你似乎在正确的轨道上,出了什么问题?

Your parameter is called 'LambdaRoleName'.您的参数称为“LambdaRoleName”。 Please be aware that it should be the role its ARN that you pass.请注意,它应该是您传递的 ARN 角色。

So when you deploy the stack, pass the role arn to the parameter:因此,当您部署堆栈时,将角色 arn 传递给参数:

aws cloudformation deploy --template-file your-template.yaml --stack-name your-stack-name --parameter-overrides LambdaRoleName=arn:aws:iam::123456789012:role/your-role --region eu-west-1

or change the default value to the role ARN:或将默认值更改为角色 ARN:

Parameters:
  LambdaRoleName:
    Default: arn:aws:iam::123456789012:role/your-role
    Type: String

It should be:它应该是:

Role: !Ref LambdaRoleName

rather then而不是

Role: !Ref ExistingRoleCreatedInAwsAccount

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

相关问题 有没有办法用 cloudformation 创建 aws lambda 执行角色? - Is there a way to create aws lambda execution role with cloudformation? 如何使用 aws cdk 代码将 iam 角色附加到现有的 redshift 集群 - How to attach iam role to existing redshift cluster using aws cdk code AWS CloudFormation:如何从另一个 AWS 账户为 Lambda 代码指定一个存储桶? - AWS CloudFormation: How to specify a bucket from another AWS account for Lambda code? 在 AWS 中切换配置文件/帐户/角色 Lambda - Switch profile/account/role in AWS Lambda 如何使用 AWS CloudFormation 连接到现有 RDS 数据库? - How can I connect to an existing RDS database using AWS CloudFormation? 如何为特定 AWS 账户运行 CloudFormation - How to run CloudFormation for a specific AWS Account 如何为使用 CloudFormation 模板创建的 AWS Lambda function 添加触发器? - How to add triggers for a AWS Lambda function created using a CloudFormation template? CloudFormation 模板 - 将现有 IAM 角色用于 Lambda 函数 - CloudFormation template - Using existing IAM role in for Lambda functions CloudFormation 堆栈类型:“AWS::IAM::Role” - CloudFormation Stack Type: 'AWS::IAM::Role' 在 CloudFormation 模板中使用现有角色 - Using Existing Role in CloudFormation Template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM