typescriptamazon-web-servicesamazon-s3aws-cdkamazon-glacier

How to create AWS S3 Glacier vault in CDK app by using TypeScript?


Is it possible to create AWS S3 Glacier vault in CDK app by using TypeScript? I don't see TypeScript option in the developer guide: https://docs.aws.amazon.com/amazonglacier/latest/dev/creating-vaults.html

We can configure Intelligent Tiering for AWS S3 bucket, but I don't think that it's what I am looking for. I found Creating a S3 Glacier vault dev guide for JavaScript SDK which describes the process of creating the vault. This is exactly what I need, but I doubt I could use it in CDK TypeScript app.

Anyway. I tried to use aws-sdk/client-glacier NPM package. I installed it and created a new instance of the GlacierClient class in cdk.ts file. Unfortunately, I wasn't able to build the app.

enter image description here

Here is my package.json file.

{

  "name": "cdk-app-2",

  "version": "0.1.0",

  "bin": {

    "cdk-app-2": "bin/cdk-app-2.js"

  },

  "scripts": {

    "build": "tsc",

    "watch": "tsc -w",

    "test": "jest",

    "cdk": "cdk"

  },

  "devDependencies": {

    "@types/jest": "^27.5.2",

    "@types/node": "10.17.27",

    "@types/prettier": "2.6.0",

    "aws-cdk": "2.50.0",

    "jest": "^27.5.1",

    "ts-jest": "^27.1.4",

    "ts-node": "^10.9.1",

    "typescript": "~3.9.7"

  },

  "dependencies": {

    "@aws-sdk/client-glacier": "^3.204.0",

    "aws-cdk-lib": "2.50.0",

    "constructs": "^10.0.0",

    "source-map-support": "^0.5.21"

  }

}

Solution

  • S3 Glacier is not supported in either the CDK or CloudFormation.

    As a workaround, add a Custom Resource construct. The Custom Resource's job is to call the SDK APIs to create/update/delete the vault. It will be invoked during the deployment lifecycle by CloudFormation. There are several flavours of Custom Resource. You may be able to use the custom_resources.AwsCustomResource construct, which makes SDK calls easy. If more control is required, you will need to write your own Lambda in conjunction with a cdk.CustomResource.