代码之家  ›  专栏  ›  技术社区  ›  Brooks

未知云信息错误/执行变更集失败

  •  3
  • Brooks  · 技术社区  · 9 年前

    我正在努力设置Java AWS lambda函数,以便通过Codepipeline进行部署->云形成,我在云形成方面有一些困难。我以前使用过Terraform,所以我理解一般概念。。。

    现在,我只是在标记样本模板。Codestar在存储库中创建的yml文件,因此是HelloWorld引用。

    Error: Failed to execute change set: ChangeSet [arn:aws:cloudformation:us-east-1:XXXXXXXXXXXX:stack/awscodestar-test2-lambda/07e71ee0-6a73-11e7-bee5-50d5cd24fac6] cannot be executed in its current execution status of [EXECUTE_FAILED]
    

    我做错了什么?我没有很好地掌握Fn::GetAtt调用,但我尝试了几种不同的方法,但没有任何乐趣。

    **除了找出问题所在外,我还有两个问题:

    1. 请解释我在Fn::GetAtt函数调用中应该引用什么?这是我在试图调用的资源顶部提供的资源名称吗(例如GetHelloWorld)?或者作为该资源的属性提供的显式名称(即FunctionName)?

    2. 在Lambda函数声明中,我尝试在线设置事件触发器,然后需要引用Lambda函数。我可以从嵌套在Lambda函数资源中的事件声明中引用Lambda函数资源吗??

    下面是我的模板。yml文件。

    AWSTemplateFormatVersion: 2010-09-09
    Transform:
    - AWS::Serverless-2016-10-31
    - AWS::CodeStar
    
    Parameters:
      ProjectId:
        Type: String
        Description: AWS CodeStar projectID used to associate new resources to team members
    
    Resources:
      RoleForLambda:
        Type: "AWS::IAM::Role"
        Properties: 
          AssumeRolePolicyDocument:
            Version: "2012-10-17"
            Statement: 
              - Effect: "Allow"
                Principal: 
                  Service: "lambda.amazonaws.com"
                Action: "sts:AssumeRole"
          Policies:
          - PolicyName: s3put
            PolicyDocument:
              Version: "2012-10-17"
              Statement:
              - Effect: "Allow"
                Action:
                - 'logs:CreateLogGroup'
                - 'logs:CreateLogStream'
                - 'logs:PutLogEvents'
                - 's3:PutObject'
                Resource: 
                - 'arn:aws:logs:*:*:*'
                - 'arn:aws:s3:*'
      GetHelloWorld:
        Type: AWS::Serverless::Function
        Properties:
          Handler: com.aws.codestar.projecttemplates.handler.HelloWorldHandler
          Runtime: java8
          Timeout: 60
          MemorySize: 256
          Role:
            'Fn::GetAtt':
              - RoleForLambda
              - Arn
        ScheduleRule:
          Type: 'AWS::Events::Rule'
          Properties:
            Name: DownloadFiles
            ScheduleExpression: 'cron(2,7,12,17,22,27,32,37,42,47,52,57 * * * ? *)'
            State: ENABLED
            Targets:
              - Arn: 
                  'Fn::GetAtt':
                    - GetHelloWorld
                    - Arn
                Id: downloadFiles
        LambdaInvokePermission:
          Type: "AWS::Lambda::Permission"
          Properties: 
            Action: lambda:InvokeFunction
            FunctionName: GetHelloWorld
            Principal: events.amazonaws.com
            SourceAccount: AWS::XXXXXXXXXXXX
            SourceArn:
              - Arn:
                  'Fn::GetAtt':
                    - ScheduleRule
                    - Arn
    
    2 回复  |  直到 9 年前
        1
  •  4
  •   Brooks    9 年前

    以防其他人遇到类似问题。事实证明,我有一些语法错误,我确信还有其他问题……这是一个工作模板。

    AWSTemplateFormatVersion: 2010-09-09
    Description: >-
      This Lambda function does something
    Parameters:
      ProjectId:
        Description: AWS CodeStar projectID used to associate new resources to team members
        Type: String
    Resources:
      DownloadRole:
        Type: 'AWS::IAM::Role'
        Properties:
          AssumeRolePolicyDocument:
            Version: 2012-10-17
            Statement:
              - Sid: ''
                Effect: Allow
                Principal:
                  Service: lambda.amazonaws.com
                Action: 'sts:AssumeRole'
          Policies:
            - PolicyName: PutS3Policy
              PolicyDocument:
                Version: 2012-10-17
                Statement:
                  - Effect: Allow
                    Action:
                      - 'logs:CreateLogGroup'
                      - 'logs:CreateLogStream'
                      - 'logs:PutLogEvents'
                      - 's3:PutObject'
                      - 's3:PutObjectAcl'
                      - 's3:PutObjectTagging'
                      - 'sns:Publish'
                    Resource:
                      - 'arn:aws:logs:*:*:*'
                      - 'arn:aws:s3:::myBucket'
                      - 'arn:aws:s3:::myBucket/*'
                      - 'arn:aws:sns:us-east-1:xxxxxxxxxxxx:SNS_TOPIC'
          Path: /
      DownloadFunction:
        Type: 'AWS::Lambda::Function'
        Properties:
          Handler: 'com.mycompany.download.LambdaFunction::lambdaHandler'
          MemorySize: '256'
          Description: A scheduled Lambda function
          FunctionName: Download
          Role: !GetAtt 
            - DownloadRole
            - Arn
          Runtime: java8
          Timeout: '60'
        DependsOn:
          - DownloadRole
      ScheduleRule:
        Type: 'AWS::Events::Rule'
        Properties:
          Name: DownloadFiles
          ScheduleExpression: 'cron(2,7,12,17,22,27,32,37,42,47,52,57 * * * ? *)'
          State: ENABLED
          Targets:
            - Arn: !GetAtt 
                - DownloadFunction
                - Arn
              Id: DownloadFiles
        DependsOn:
          - DownloadFunction
      LambdaInvokePermission:
        Type: 'AWS::Lambda::Permission'
        Properties:
          FunctionName: !GetAtt 
            - DownloadFunction
            - Arn
          Action: 'lambda:InvokeFunction'
          Principal: events.amazonaws.com
          SourceArn: !GetAtt 
            - ScheduleRule
            - Arn
        DependsOn:
          - DownloadFunction
          - ScheduleRule
    
        2
  •  1
  •   Francois Harmse    4 年前

    也许不是完全相同的问题 这是我们的错误消息:

    调用ExecuteChangeSet操作时出错(InvalidChangeSetStatus):无法在其当前执行状态[OBSOLETE]下执行ChangeSet[arn:aws:cloudformation:..]