Search code examples
amazon-web-servicesaws-cloudformationaws-glue

Glue connection not working through cloudformation. It is giving error : Unable to resolve any valid connection


My glue connection created through cloudformation is not working whereas if create a glue connection with same configuration through the console it works perfectly fine. Please find the code for the same :

Resources:
Policy1:
Type: AWS::IAM::ManagedPolicy
Properties: 
  Description: Policy for glue
  PolicyDocument: 
    Version: "2012-10-17"
    Statement:
    - Effect: Allow
      Action: '*'
      Resource: '*'
Role1:
Type: AWS::IAM::Role
DependsOn: Policy1
Properties: 
  AssumeRolePolicyDocument:
    Version: "2012-10-17"
    Statement:
    - Effect: Allow
      Principal:
        Service:
          - glue.amazonaws.com
          - rds.amazonaws.com
      Action:
        - 'sts:AssumeRole'
  ManagedPolicyArns: 
      - !Ref Policy1
GlueConnection:
Type: AWS::Glue::Connection
Properties: 
  CatalogId: !Ref AWS::AccountId
  ConnectionInput: 
    ConnectionProperties: 
      JDBC_CONNECTION_URL: "jdbc:mysql://database-2.cxs4adwnjt5i.ap-south-1.rds.amazonaws.com:3306/mydb"
      USERNAME: "admin"
      PASSWORD: "Admin123"
      JDBC_ENFORCE_SSL: False
    ConnectionType: JDBC
    PhysicalConnectionRequirements: 
      SecurityGroupIdList: 
        - sg-065781f0ee39344fa
      SubnetId: subnet-0cdac25848264fdb8
    Name: rds-1
GlueDatabase:
Type: AWS::Glue::Database
Properties: 
  CatalogId: !Ref AWS::AccountId
  DatabaseInput: 
    Name: my-rds-glue-1

Solution

  • To fix this you need to include AvailabilityZone in PhysicalConnectionRequirements.

    PhysicalConnectionRequirements:
      AvailabilityZone: !Select [ 0, !GetAZs  '' ] 
      SecurityGroupIdList: 
        - !Ref GlueSG
      SubnetId: !Ref  SubnetId
    

    See more details here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-connection-physicalconnectionrequirements.html

    Until this gets fix the workaround is, like you mentioned, to go in the console and just edit and save the connection.