amazon-web-services - 如何通过其友好名称或使用 cloudformation 的 arn 从云上现有的 Lambda 函数获取角色名称?

标签 amazon-web-services aws-lambda aws-cloudformation amazon-iam aws-secrets-manager

我创建了一个用于 RDS 轮换 secret 的 CFN 模板。它由一个需要自动生成角色的 AWS HostedLambda 组成。我想为该角色附加另一个策略。

  rRotationLambdaDecryptPolicy:
    Type: AWS::IAM::ManagedPolicy
    DependsOn: rSecretRotationScheduleHostedRotationLambda
    Properties:
      Description: "Providing access to HostedLambda for decrypting KMS"
      ManagedPolicyName: CustomedHostedLambdaKmsUserRolePolicy
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
        - Sid: AllowLambdaDecryptKMS
          Effect: Allow
          Action:
            - kms:Decrypt
            - kms:CreateGrant
          Resource:
          - !Sub arn:aws:kms:*:${AWS::AccountId}:key/*
          Condition:
            ForAnyValue:StringLike:
              kms:ResourceAliases: alias/SecretsManager_KMSKey
      Roles: <friendly rolename>

问题是我知道 Lambda 友好名称及其 Arn。需要找到链接到此 lambda 的角色名称,以便我可以将上述策略附加到它(将其友好名称添加到角色)。

尝试在下面附加此内容

      Roles: 
        Fn::Join:
          - ""
          - - '"'
            - Fn::GetAtt:
              - !Sub 'arn:aws:lambda::${AWS::AccountId}:function:SecretsManager-research-creds-rotation-lambda'
              - Role
            - '"'

P.S.- 此处不能使用 importvalue,因为嵌套堆栈是由 AWS 创建的,并且其输出不包含导出。

使用的 Lambda:-

  rSecretRotationSchedule:
    Type: AWS::SecretsManager::RotationSchedule
    Properties:
      SecretId:<SecretId>
      HostedRotationLambda:
        KmsKeyArn: <KmsKeyArn>
        MasterSecretArn: <MasterSecretArn>
        MasterSecretKmsKeyArn: <MasterSecretKmsKeyArn>
        RotationType: PostgreSQLMultiUser
        RotationLambdaName: SecretsManager-research-creds-rotation-lambda
        VpcSecurityGroupIds: <VpcSecurityGroupIds>
        VpcSubnetIds: <VpcSubnetIds>
      RotationRules:
        AutomaticallyAfterDays: 60

下面是我引用模板的链接:- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-rotationschedule.html

最佳答案

很可能您无法使用普通 CFN 来做到这一点。您必须开发一个 custom resource 。这将采用新的 lambda 函数的形式,该函数将使用 AWS SDK 来查询主 lambda 函数的属性。一旦自定义资源找到角色名称,它会将其返回到您的堆栈以供进一步使用。

关于amazon-web-services - 如何通过其友好名称或使用 cloudformation 的 arn 从云上现有的 Lambda 函数获取角色名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69160971/

相关文章:

amazon-web-services - AWS S3 操作不适用于声明中的任何资源

amazon-web-services - AWS lambda 音频特征提取(存储层数不足)

google-cloud-platform - GCP Function 有多少磁盘空间?

amazon-web-services - 不应用 AWS 堆栈集实例的覆盖参数

aws-cloudformation - 云信息 : How to append properties to a pre-defined bucket?

amazon-web-services - s3 - 比较两个桶之间的文件

amazon-web-services - 星型模式会在 Redshift 中受益吗?

amazon-web-services - 在现实世界中扩展 Docker 容器

node.js - Lambda 函数无法在 S3 上创建文件

aws-cloudformation - 云形成模板设计