Setting the file. One moment.
Chapter 10 · Azure Cloud Migrate
Subchapter 10.4
references/services/app-service/code-migration.mdMarkdown5 KBView on GitHub
Migrate source platform web application code to Azure App Service.
mcp_azure_mcp_get_azure_bestpractices tool<source-folder>-azure/ — never modify the source directorymcp_azure_mcp_get_azure_bestpractices tool for App Service guidance/healthz endpoint for App Service health monitoringFor non-Docker deployments, configure the startup command in App Service:
| Runtime | Default Start | Custom Start |
|---|---|---|
| Node.js | npm start | Set in Configuration → General Settings |
| Python | gunicorn app:app | gunicorn --bind=0.0.0.0 --timeout 600 app:app |
| Java | Auto-detected | -Dserver.port=80 |
| .NET | Auto-detected | dotnet myapp.dll |
Use a Dockerfile when the app requires custom system dependencies or multi-process setups:
FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 8080
CMD ["node", "server.js"]⚠️ Port: App Service injects
PORTenv var. Always bind toprocess.env.PORT || 8080.
// Add as FIRST import in entry point
const appInsights = require('applicationinsights');
appInsights.setup(process.env.APPLICATIONINSIGHTS_CONNECTION_STRING)
.setAutoCollectRequests(true)
.setAutoCollectExceptions(true)
.start();| Source | Azure Target | Connection Pattern |
|---|---|---|
| RDS PostgreSQL | Azure Database for PostgreSQL Flexible Server | Managed identity + @azure/identity |
| RDS MySQL | Azure Database for MySQL Flexible Server | Managed identity + @azure/identity |
| RDS SQL Server | Azure SQL Database | Managed identity + @azure/identity |
| Heroku Postgres | Azure Database for PostgreSQL Flexible Server | Managed identity |
| Cloud SQL | Azure SQL / PostgreSQL Flexible Server | Managed identity |
| MongoDB Atlas | Azure Cosmos DB for MongoDB | Connection string → managed identity |
const { DefaultAzureCredential } = require('@azure/identity');
const { Client } = require('pg');
async function main() {
const credential = new DefaultAzureCredential({
managedIdentityClientId: process.env.AZURE_CLIENT_ID
});
const token = await credential.getToken('https://ossrdbms-aad.database.windows.net/.default');
const client = new Client({
host: process.env.PGHOST,
database: process.env.PGDATABASE,
user: process.env.PGUSER,
password: token.token,
ssl: { rejectUnauthorized: true },
port: 5432
});
await client.connect();
// ... use client
}
main().catch(console.error);⚠️ Wrap in
async function main()— top-levelawaitis not supported in CommonJS or many Node.js entrypoints. For ESM, top-level await works only with"type": "module"inpackage.json.
If the source app serves static assets, consider:
| Source Pattern | Azure Equivalent |
|---|---|
| Heroku Worker dyno | WebJobs (continuous) or separate Container App |
| Beanstalk Worker tier | WebJobs or Azure Functions |
| App Engine service (worker) | WebJobs or Azure Functions |
| Cron jobs | WebJobs (triggered) or Azure Functions Timer trigger |
After code migration is complete:
migration-status.md — mark Code Migration as ✅ Completeazure.yaml and .azure/preparation-manifest.md