First one i install all tools in my MacBook Air(M1 Chips)
brew install node
brew install awscli
npm install -g typescript
npm install -g aws-cdk
cdk init app - language typescript
homebrew is like apt-get, yum install package tools, if you don’t know how to install you can follow the like https://brew.sh/
then input your aws access key
aws configure
AWS Access Key ID [None]: AKIAVQIDVKBCQZJ2BQEE
AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Default region name [None]: ap-southeast-1
Default output format [None]: text
if you don’t know how to create your access key, you can follow it
Create your access key in aws IAM
give some tag to know what is it
you need download csv and done
after you can input access key in your command line
then create project, the code is use typescript to create, command will auto create template code, Details please check in AWS , CDK support too many language.
https://docs.aws.amazon.com/cdk/v2/guide/getting\_started.html
mkdir s3
cd s3
cdk init app --language typescript
s3 is your project
in the picture, it like your project tree, you develop in lib and project-stack.ts
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import {aws_s3} from "aws-cdk-lib";
// import * as sqs from 'aws-cdk-lib/aws-sqs';
export class S3Stack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const s3 = new aws_s3.Bucket(this, 'MyEncryptedBucket', {
encryption: aws_s3.BucketEncryption.KMS,
bucketKeyEnabled: true,
bucketName: "webproject202302130146"
});
// The code that defines your stack goes here
// example resource
// const queue = new sqs.Queue(this, 'S3Queue', {
// visibilityTimeout: cdk.Duration.seconds(300)
// });
}
}
here have example code, you can follow it create your bucket.
!!!!!be careful the bucketName, cannot same in the world
cdk bootstrap
cdk deploy
it will create your cdk policy in your aws iam policy and role for create something base your cdk code
it should auto create cdktoolkit stack in your cloudformation
you can check it in your s3 console
so, it is easily to create your first resource use cdk
Next stage to teach you how to create application use cdk
Next stage: create s3 with cloudfront speed up your serverless website
REF:
https://brew.sh/
https://docs.aws.amazon.com/cdk/v2/guide/getting\_started.html
Top comments (0)