【问题标题】:AWS Automation Document not updating Lambda AliasAWS 自动化文档未更新 Lambda 别名
【发布时间】:2021-10-08 01:48:47
【问题描述】:

我使用云形成创建了一个自动化文档来更新给定函数的 live 别名。它运行正常,没有任何错误,我没有看到任何云迹。但是当我检查哪个版本设置为alias:live 时,它保持不变。

模板.yml

AWSTemplateFormatVersion: "2010-09-09"
Description: "AWS CloudFormation Template for Response Plans"
Parameters:
  Environment:
    Type: String
    Default: "sandbox"
  Domain:
    Type: String
  Team:
    Type: String
  NotificationARN:
    Type: AWS::SSM::Parameter::Value<String>
Resources:
  ResponsePlan:
    Type: AWS::SSMIncidents::ResponsePlan
    Properties:
      Actions:
        - SsmAutomation:
            RoleArn: !GetAtt Role.Arn
            DocumentName: UpdateAliasDocument
      DisplayName: "UpdateLambdaAlias"
      IncidentTemplate:
        Impact: 3
        NotificationTargets:
          - SnsTopicArn:
              Ref: NotificationARN
        Summary: "String"
        Title: "String"
      Name: "UpdateLambdaAlias"
      Tags:
        - Key: "Team"
          Value: !Ref Team
        - Key: "Domain"
          Value: !Ref Domain
        - Key: "Environment"
          Value: !Ref Environment
  Document:
    Type: AWS::SSM::Document
    Properties:
      Content:
        schemaVersion: "2.2"
        parameters:
          FunctionVersion:
            type: "String"
            default: "1"
          FunctionName:
            type: "String"
        mainSteps:
          - name: "UpdateLambdaAlias"
            action: aws:runShellScript
            inputs:
              runCommand:
                - aws lambda update-alias --function-name {{FunctionName}} --name live --function-version {{FunctionVersion}}
      DocumentType: "Command"
      TargetType: /
      Tags:
        - Key: "Team"
          Value: !Ref Team
  Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - lambda.amazonaws.com
            Action: sts:AssumeRole
      Path: /
      Policies:
        - PolicyName: EC2Instances
          PolicyDocument:
            Statement:
              - Effect: Allow
                Action:
                  - ec2:*
                Resource:
                  - !Sub arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:instance/*
        - PolicyName: UpdateAliasPolicy
          PolicyDocument:
            Statement:
              - Effect: Allow
                Action:
                  - lambda:UpdateFunctionConfiguration
                Resource:
                  - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${Environment}-*
  Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0c2b8ca1dad447f8a
      InstanceType: t2.micro
      Monitoring: true
      Tags:
        - Key: "Team"
          Value: !Ref Team

更新

似乎没有找到运行脚本的目标

【问题讨论】:

  • 你检查过CloudWatch logs吗?
  • 那里也看不到任何东西。不知道在那里寻找什么。我去群里找了函数,搜索了alias,但是什么都没返回。

标签: aws-lambda amazon-cloudformation aws-ssm aws-systems-manager aws-automation


【解决方案1】:

您的Role 条目似乎没有执行update-alias 命令所需的权限。您的政策只允许lambda:UpdateFunctionConfiguration

您至少还需要lambda:UpdateAlias 权限。如果这还不够,您可以尝试对您的角色非常宽容,然后再减少权限。

【讨论】:

  • 感谢您的关注。但看起来我仍然需要一个 EC2 实例来执行,但目标列表中没有可用的实例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-02
  • 2018-12-21
  • 1970-01-01
  • 2018-09-19
  • 2018-07-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多