aws lambda_AWS CloudFormation:目标组没有关联的负载均衡器

aws lambda

aws lambda

昨天,我使用AWS CloudFormation模板最终创建了ECS服务(Fargate类型),还创建了包括应用程序负载平衡器,目标组和IAM角色的资源。

创建堆栈时,出现以下错误:

具有targetGroupArn arn:aws:elasticloadbalancing:us-east-1:599074885545:targetgroup / a204516-S2S-Sandbox-TargetGroup / 9f4aa2eb4051a952的目标组没有关联的负载平衡器。 (服务:AmazonECS;状态代码:400;错误代码:InvalidParameterException;请求ID:5da2a1ed-a216-4666-a6f9-8af18ef37af6)

The target group with targetGroupArn arn:aws:elasticloadbalancing:us-east-1:999999995545:targetgroup/MyTargetGroup/999999eb4051a952 does not have an associated load balancer. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: 54321987-a2a2-4444-abcd-8af18ef12345)

我检查了我的模板很多次,并认为它是正确的。 我在论坛上发现了一条帖子,提示该错误可能是由于在创建ECS服务时可能尚未创建负载均衡器。

解决方案:将DependsOn属性用于ECS服务资源。

这是我的AWS CloudFormation模板的一部分,使用DependsOn属性:

 #Create Application Load Balancer

  DemoApplicationLoadBalancer:

    Type: AWS::ElasticLoadBalancingV2::LoadBalancer

    Properties:

      Type: application

      Name: Demo-ALB

      IpAddressType: ipv4

      Scheme: internet-facing

      # Other properties...
 # Create Security Groups, IAM Roles, Load Balancing Listener, ECS Cluster, ECS Task Def, etc.
 # Create ECS Service - with DependsOn attribute

  DemoSandboxService:

    Type: AWS::ECS::Service

    DependsOn:

    - DemoLoadBalancerListener

    Properties:

      Cluster:

          Ref: DemoSandboxCluster

      # Other properties...

翻译自: https://www.javacodegeeks.com/2020/06/aws-cloudformation-target-group-does-not-have-an-associated-load-balancer.html

aws lambda

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在AWS云上使用Java,您可以使用Lambda函数来运行Java代码。Lambda函数是一种无服务计算服务,可以让您运行代码而无需管理服务。您可以将Java代码打包成一个JAR文件,并将其上传到Lambda函数中。然后,您可以使用API Gateway来创建API端点,以便您的应用程序可以与Lambda函数通信。 以下是使用CloudFormation创建Lambda函数和API Gateway的步骤: 1. 编写Lambda函数代码,并将其打包成JAR文件。您可以使用Maven或Gradle等构建工具来构建和打包代码。 2. 使用CloudFormation模板定义Lambda函数和API Gateway。下面是一个简单的模板示例: ``` Resources: MyLambdaFunction: Type: AWS::Lambda::Function Properties: Code: S3Bucket: my-bucket S3Key: my-lambda-function.jar Handler: com.example.MyLambdaFunctionHandler::handleRequest Role: !GetAtt MyLambdaExecutionRole.Arn Runtime: java8 MyApiGateway: Type: AWS::ApiGateway::RestApi Properties: Name: my-api-gateway MyApiGatewayResource: Type: AWS::ApiGateway::Resource Properties: ParentId: !GetAtt MyApiGateway.RootResourceId PathPart: my-resource MyApiGatewayMethod: Type: AWS::ApiGateway::Method Properties: RestApiId: !Ref MyApiGateway ResourceId: !Ref MyApiGatewayResource HttpMethod: GET AuthorizationType: NONE Integration: Type: AWS_PROXY IntegrationHttpMethod: POST Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambdaFunction.Arn}/invocations MyLambdaExecutionRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: lambda.amazonaws.com Action: sts:AssumeRole Policies: - PolicyName: MyLambdaExecutionPolicy PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents Resource: arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/my-lambda-function:* ``` 该模板定义了一个Lambda函数,一个API Gateway,一个API Gateway资源和一个API Gateway方法。API Gateway方法使用AWS_PROXY集成类型,以便将请求传递给Lambda函数。 3. 使用CloudFormation部署模板。您可以使用AWS CLI或AWS管理控制台等工具来部署模板。 4. 测试API端点。使用API Gateway提供的URL测试API端点,并确保它可以正常工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值