빠른 시작: Azure 및 Azure MCP 서버에 GitHub Copilot 사용하여 Azure Cache for Redis 사용하여 앱 만들기 및 배포

이 빠른 시작에서는 다음과 같은 간단한 Python 앱을 만드는 방법을 보여줍니다.

  • Azure Cache for Redis에 연결합니다.
  • 현재 날짜 및 시간을 Redis에 씁니다.
  • 값을 다시 읽습니다.
  • 결과를 콘솔에 인쇄합니다.

GitHub Copilot를 사용하여 대부분의 코드 및 프로비저닝 단계를 생성합니다.

사전 요구 사항

전체 설치 지침은 시작 문서를 참조하세요. 다음 항목이 있는지 확인합니다.

Important

GitHub Copilot는 GitHub에서 관리하는 별도의 구독입니다. GitHub Copilot 구독 및 지원에 대한 질문은 GitHub Copilot 계획 시작을 참조하세요.

Important

GitHub Copilot는 GitHub에서 관리하는 별도의 구독입니다. GitHub Copilot 구독 및 지원에 대한 질문은 GitHub Copilot 계획 시작을 참조하세요.

Important

GitHub Copilot는 GitHub에서 관리하는 별도의 구독입니다. GitHub Copilot 구독 및 지원에 대한 질문은 GitHub Copilot 계획 시작을 참조하세요.

앱 빌드

이 문서에 설명된 다음 단계를 수행합니다.

  1. 작업 영역에 .env 파일을 만들어 Azure 배포 정보를 환경 변수로 저장합니다.
  2. 구독에서 Azure Cache for Redis 인스턴스를 만드는 프롬프트를 작성합니다. Redis 연결 정보도 파일에 저장됩니다 .env .
  3. 리소스와 .env 파일이 올바르게 생성되었는지 확인합니다.
  4. 환경 변수를 사용하여 캐시에서 검색, 쓰기 및 읽을 Python 앱을 만드는 프롬프트를 작성합니다.
  5. 앱의 작동 유효성을 검사합니다.
  6. Azure 리소스를 정리합니다.

올바른 도구가 선택되어 있는지 확인합니다.

Azure MCP Server가 설치되어 있어야 하며 Azure GitHub Copilot 설치되어 있어야 합니다.

  1. 채팅 창에서 도구 구성... 아이콘을 선택합니다.
  2. 구성 도구 가 명령 팔레트에 표시됩니다. "Azure MCP" 및 "Azure GitHub Copilot"의 최상위 노드가 모두 선택되어 있는지 확인합니다.
  1. 채팅 창에서 도구 선택... 아이콘을 선택합니다.
  2. 도구 선택 메뉴가 표시됩니다. "Azure MCP Server" 최상위 노드가 선택되어 있는지 확인합니다.
  1. 채팅 창에서 도구 선택 아이콘을 선택합니다.
  2. 도구 선택 메뉴가 표시됩니다. "Azure" 및 "Azure MCP"의 최상위 노드가 모두 선택되어 있는지 확인합니다.

로컬 환경 변수 만들기

일반적인 개발 방법은 중요한 키 및 기타 설정을 작업 영역 폴더의 파일에 환경 변수로 .env 저장하는 것입니다. 이렇게 하면 모든 구성이 프로젝트 내에 자체 포함됩니다.

Important

.gitignore 파일에 .env을 반드시 포함하여 비밀을 실수로 소스 제어에 커밋하지 않도록 확인하세요.

이 단계에서는 다음과 같은 프롬프트를 사용하여 작업 공간에 .env 파일을 만듭니다.

Create a .env file in this workspace with the following environment variables filled in:

AZURE_SUBSCRIPTION_ID
AZURE_TENANT_ID
AZURE_LOCATION
AZURE_RESOURCE_GROUP
AZURE_RESOURCE_PREFIX

Use my <your-subscription-name> subscription and I want to put everything in eastus.

<your-subscription-name> Azure 구독의 이름으로 바꿉다. Copilot 구독 및 테넌트 ID를 조회하고, 리소스 그룹 이름 및 접두사를 생성하고, .env 파일을 만듭니다.

파일을 만든 후 파일을 열고 값이 올바른지 확인합니다.

AZURE_SUBSCRIPTION_ID=<your-azure-subscription-id>
AZURE_TENANT_ID=<your-azure-tenant-id>
AZURE_LOCATION=eastus
AZURE_RESOURCE_GROUP=<resource-group>
AZURE_RESOURCE_PREFIX=<resource-prefix>

Azure Cache for Redis 만들기

GitHub Copilot Chat 열고 다음 프롬프트를 붙여넣습니다.

You have access to Azure MCP tools.

Use the variables in the `.env` file in this workspace to create an Azure Cache for Redis instance.

Tasks:
1. Ensure the resource group exists.
2. Create Azure Cache for Redis:
    - Name: {AZURE_RESOURCE_PREFIX}-redis
    - SKU: Basic C0
    - TLS enabled (port 6380)
3. Write the following values into the `.env` file:
    REDIS_HOST
    REDIS_PORT=6380
    REDIS_PASSWORD (primary key)
    REDIS_SSL=true

Important:
- Use Azure MCP to create resources and fetch keys.

Copilot Redis 리소스를 만든 다음 호스트 이름, 기본 키 및 기타 환경 변수를 포함하는 .env 파일을 만듭니다.

.env 파일에 Redis 설정이 있는지 확인합니다.

  1. .env 프로젝트 폴더에서 파일을 열고 값이 있는지 확인합니다.

    REDIS_HOST=<your-cache-name>.redis.cache.windows.net
    REDIS_PORT=6380
    REDIS_PASSWORD=<primary-key>
    REDIS_SSL=true
    
  2. 다음 프롬프트를 사용하여 Azure Cache for Redis 인스턴스가 실행되고 있는지 확인합니다.

    Use the values in the `.env` file in this workspace to validate that an instance of Azure Cache for Redis is running and ready to be used.
    

Python 앱을 작성하라는 메시지 표시

다음 프롬프트를 사용하여 Azure Cache for Redis 새 인스턴스를 작성하고 읽는 Python 앱을 만듭니다.

Create a minimal Python console app in this workspace.

Important:
- Do ALL work directly by editing files.
- Do NOT ask me to copy/paste code.
- Create files if they do not exist.

Goal:
Build a simple app that writes the current date/time to Azure Cache for Redis, reads it back, and prints results to the console.

Project requirements:

1. Create or update these files:

- main.py
- requirements.txt
- .gitignore

2. requirements.txt must include:
- redis
- python-dotenv

3. .gitignore must include:
- .venv/
- __pycache__/
- .env

4. main.py must:

- Load environment variables using python-dotenv
- Read:
    REDIS_HOST
    REDIS_PORT
    REDIS_PASSWORD
    REDIS_SSL
- Connect to Azure Cache for Redis using TLS (ssl=True when REDIS_SSL=true)
- Use decode_responses=True
- Test connection with PING and print:
    Connected to Redis
- Write current datetime (ISO format) to key:
    demo:timestamp
- Read the value back
- Print exactly:

    WROTE: <value>
    READ : <value>

- Wrap connection logic in a try/except and print a helpful error message.

5. Keep the code simple and beginner-friendly:
- Single file
- No classes
- About 40–60 lines

After editing the files:
- Show a summary of what you changed.
- Do NOT print the full file contents unless I ask.

Python 앱 유효성 검사

  1. 프롬프트에서 요청한 파일이 있는지 확인합니다. 파일을 시각적으로 검사하여 적절한 값이 있는지 확인합니다.

  2. main.py 파일을 검사하여 .env 파일에서 값을 검색하고, redis 패키지를 가져오고, Azure Cache for Redis 연결합니다. 캐시를 작성하고 읽는지 확인합니다. 다음 코드와 유사한 코드가 표시될 수 있습니다.

    
    import os
    from datetime import datetime
    from dotenv import load_dotenv
    import redis
    
    # Load local environment variables
    load_dotenv()
    
    host = os.getenv("REDIS_HOST")
    port = int(os.getenv("REDIS_PORT", "6380"))
    password = os.getenv("REDIS_PASSWORD")
    ssl_enabled = os.getenv("REDIS_SSL", "true").lower() == "true"
    
    try:
        client = redis.Redis(
            host=host,
            port=port,
            password=password,
            ssl=ssl_enabled,
            decode_responses=True
        ) 
    
        # Verify connection
        client.ping()
        print("Connected to Redis")
    
        # Write current time
        now = datetime.now().isoformat()
        client.set("demo:timestamp", now)
        print(f"WROTE: {now}")
    
        # Read value back
        value = client.get("demo:timestamp")
        print(f"READ : {value}")
    
    except Exception as ex:
        print("Connection failed.")
        print(ex)
    

    Important

    AI 지원 소프트웨어 개발은 비결정적이므로 동일한 코드가 두 번 생성되지 않습니다. 그러나 이와 같은 간단한 애플리케이션에서는 기본 접근 방식, 구문 및 최종 결과가 비록 정확히 같을 필요는 없지만 유사해야 합니다.

앱 실행

터미널에서 앱을 실행합니다.

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python main.py

다음과 유사한 출력이 표시됩니다.

Connected to Redis
WROTE: 2026-03-01T10:22:11.452331
READ : 2026-03-01T10:22:11.452331

자원을 정리하세요

다음 프롬프트를 사용합니다.

I am finished with this instance. Please remove the Azure Cache for Redis that you created earlier by using the values in the `.env` file. ONLY remove this resource and nothing else.
  • GitHub Copilot for Azure가 무엇인지 그리고 그것이 어떻게 작동하는지 이해하기.
  • GitHub Copilot for Azure를 소프트웨어 개발 프로세스에 포함하는 방법을 이해하려면 quickstart를 따르십시오. 이 빠른 시작에서는 서비스를 배포하여 Azure 상태를 모니터링하고 문제를 해결하는 방법을 설명합니다.
  • Azure, Azure 계정, 구독 및 리소스에 대해 자세히 알아보려면 예제 프롬프트를 참조하세요.
  • Azure애플리케이션을 디자인하고 개발하는 데 관한 예제 프롬프트를 참조하세요.
  • Azure에 애플리케이션을 배포하는 방법에 대한 예제 프롬프트를 참조하세요.
  • Azure 리소스의 문제 해결 대한 예제 프롬프트를 참조하세요.