Not able to deploy to SQL Server using dacpac AWS

0

Hi AWS, this is a follow up question for https://repost.aws/questions/QUtlPI4WXKTESVA-oSK8F4xw/ci-cd-for-rds-sql-server. I am trying to create CI/CD pipeline for MSSQL Server. Here is the CI/CD code:

name: CI/CD pipeline for MSSQL Server using GitHub Actions
on:
  push:
    branches: [ main ]
env:
  AWS_BUCKET_NAME: ${{ secrets.AWS_BUCKET_NAME }}
  DB_ENDPOINT: ${{ secrets.DB_ENDPOINT }}

jobs:
  BuildDacpac:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v3.3.0
      
      - name: Build Database project
        run: |
          dotnet build --configuration Release /p:NetCoreBuild=true

      - name: Zip the deployment package
        shell: powershell
        run: Compress-Archive -Path "D:\a\sql-server-cicd-demo\sql-server-cicd-demo\" -DestinationPath "D:\a\sql-server-cicd-demo\sql-server-cicd-demo\sql-server-db.zip"
      
      - name: Set AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.AWS_REGION }}
           
      - name: Publish the artifacts to S3
        shell: cmd
        run: |
          aws s3 cp D:\a\sql-server-cicd-demo\sql-server-cicd-demo\sql-server-db.zip s3://${{ env.AWS_BUCKET_NAME }}/sql-server-cicd/

# Deploy dacpac job
  DeploySQL2022Updates:
    needs: BuildDacpac
    runs-on: [ self-hosted, Windows, X64, db-cicd-demo ]
    steps:
      - name: Set AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.AWS_REGION }}
      
      - name: Download the zip file from S3 to EC2 folder
        shell: powershell
        run: |
          C:\"Program Files"\Amazon\AWSCLIV2\aws s3 cp s3://${{ env.AWS_BUCKET_NAME }}/sql-server-cicd/sql-server-db.zip "C:\db-cicd-demo\db-cicd-demo\"
      
      - name: Unzipping the Zip file
        shell: powershell
        run: Expand-Archive -Path "C:\db-cicd-demo\db-cicd-demo\sql-server-db.zip" -DestinationPath "C:\db-cicd-demo\db-cicd-demo\sql-server-cicd-db" -Force
      
      - name: get sqlpackage version
        working-directory: C:\Program Files\Microsoft SQL Server\160\DAC\bin\
        run: ./SqlPackage /version
      
      - name: Deploy DACPAC to Target Server
        uses: Azure/sql-action@v2
        with:
          # The connection string, including authentication information, for the Azure SQL Server database.
          connection-string: ${{ secrets.DB_ENDPOINT }}
          # Path to DACPAC file to deploy
          path: C:\db-cicd-demo\db-cicd-demo\sql-server-cicd-db\sql-server-cicd-demo\bin\Release\GitHub-SQLServer2022-SDK-DBProject.dacpac
          action: publish
      
      # - name: Deploy DACPAC to AWS RDS
      #   shell: powershell
      #   run: |
      #     C:\Users\Administrator\.dotnet\tools\sqlpackage.exe /a:Publish /tsn:${{ env.DB_ENDPOINT }} /tdn:${{ env.DB_NAME }} /tu:${{ env.DB_USERNAME }} /tp:${{ env.DB_PASSWORD }}/sf:C:\sql-server-cicd\sql-server-cicd\sql-server-cicd-db\sql-server-cicd-demo\bin\Release\GitHub-SQLServer2022-SDK-DBProject.dacpac
      #   env:
      #     AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      #     AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      #     DB_ENDPOINT: ${{ secrets.DB_ENDPOINT }}
      #     DB_NAME: ${{ secrets.DB_NAME }}
      #     DB_USERNAME: ${{ secrets.DB_USERNAME }}
      #     DB_PASSWORD: ${{ secrets.DB_PASSWORD }}

The URL for the same is https://github.com/arjungoel/sql-server-cicd-demo/actions/runs/7706973663.

Post that I performed the deployment manually by login into the EC2 server and connect to local database. Here is the command I ran:

SqlPackage /a:Publish /tsn:"EC2AMAZ-DC3KDV1,1433" /tdn:"employee" /tu:"EC2AMAZ-DC3KDV1\Administrator" /tp:"xxxxxxxxxxxxxxxxxxxxx" /sf:"C:\db-cicd-demo\db-cicd-demo\sql-server-cicd-db\sql-server-cicd-demo\bin\Release\GitHub-SQLServer2022-SDK-DBProject.dacpac" /p:VerifyDeployment=False

and I am getting this error:

Publishing to database 'employee' on server 'EC2AMAZ-DC3KDV1,1433'. Initializing deployment (Start) Initializing deployment (Failed) *** Could not deploy package. Unable to connect to target server 'EC2AMAZ-DC3KDV1,1433'. Please verify the connection information such as the server name, login credentials, and firewall rules for the target server. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.) No connection could be made because the target machine actively refused it. Time elapsed 0:03:13.86

Please help me in spotting the issue as I have added port 1433 in the EC2 security group inbound rule.

profile picture
질문됨 3달 전252회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠