Skip to content

Latest commit

 

History

History
89 lines (68 loc) · 3.24 KB

File metadata and controls

89 lines (68 loc) · 3.24 KB

CDK Migration Guide for KMS (Keyword Management System)

This guide outlines the steps to migrate the KMS (Keyword Management System) from Serverless Framework to AWS CDK (Cloud Development Kit).

Prerequisites

  • AWS CLI configured with appropriate permissions
  • Node.js and npm installed
  • AWS CDK CLI installed (npm install -g aws-cdk)
  • Serverless Framework CLI installed (for removal of old stack)

Migration Steps

1. Deploy KMS to AWS to retain ApiGatewayRestApi

Before removing the old Serverless stack, we need to ensure that the API Gateway is retained. This step involves deploying a minimal CDK stack that imports the existing API Gateway.

./bin/deploy_bamoo.sh

The serverless.yml file has been updated to include a retention policy for the API Gateway:

resources: 
  - ${file(./serverless-configs/${self:provider.name}-resources.yml)}
  - extensions:
      ApiGatewayRestApi:
        DeletionPolicy: Retain
        UpdateReplacePolicy: Retain

2. Remove the old Serverless stack

Use the Serverless Framework CLI to remove the existing stack. Replace sit with your appropriate stage name if different.

npx sls remove --stage sit

This step removes all resources managed by the Serverless Framework except for the API Gateway, which we retained in step 1.

3. Set environment variables for API Gateway

We need to set environment variables for the existing API Gateway ID and its root resource ID. These will be used in our CDK stack.

First, set the EXISTING_API_ID:

export EXISTING_API_ID=<your-api-id>

Then, retrieve and set the ROOT_RESOURCE_ID:

export ROOT_RESOURCE_ID=$(aws apigateway get-rest-api --rest-api-id $EXISTING_API_ID --query 'rootResourceId' --output text)

Verify that both environment variables are set correctly:

echo $EXISTING_API_ID
echo $ROOT_RESOURCE_ID

4. Deploy the new CDK stack

With the environment variables set, we can now deploy our full CDK stack:

cdk deploy KmsStack

This command deploys the new KMS infrastructure using CDK, integrating with the existing API Gateway.

Post-Migration Steps

  • Verify that all resources are correctly deployed and functioning as expected.
  • Update any CI/CD pipelines to use CDK commands instead of Serverless Framework commands.
  • Remove any Serverless Framework specific files and configurations that are no longer needed.

Troubleshooting

  • If you encounter permission issues, ensure that your AWS CLI is configured with the correct credentials and has the necessary permissions.
  • If the API Gateway integration fails, double-check that the EXISTING_API_ID and ROOT_RESOURCE_ID environment variables are set correctly.

Rollback

In case of any issues during migration:

  1. You can redeploy the Serverless Framework stack.
  2. Remove the CDK stack using:
    cdk destroy KmsStack
  3. Ensure that the API Gateway and any critical resources are not accidentally deleted.

Notes

  • This migration process is designed to minimize downtime by retaining the existing API Gateway.
  • Always perform this migration in a non-production environment first to identify and resolve any potential issues.
  • Keep backups of your Serverless Framework configurations and any custom resources for reference.