Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AWSJ Harunobu Kameda authored Feb 24, 2022
1 parent 582a840 commit 82c68a7
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
Binary file added AWS CDK v2 ワークショップ.docx
Binary file not shown.
122 changes: 122 additions & 0 deletions command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
1.
mkdir hello-cdk
cd hello-cdk

2.
cdk init app --language javascript

3.
const cdk = require('aws-cdk-lib');
const s3 = require('aws-cdk-lib/aws-s3');

class HelloCdkStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);

new s3.Bucket(this, 'MyFirstBucket', {
versioned: true
});
}
}

module.exports = { HelloCdkStack }

4.
const cdk = require('aws-cdk-lib');
const s3 = require('aws-cdk-lib/aws-s3');

class HelloCdkStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);

new s3.Bucket(this, 'MyFirstBucket', {
versioned: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true
});
}
}

module.exports = { HelloCdkStack }

5.
mkdir cdk-workshop && cd cdk-workshop

6.
cdk init sample-app --language typescript

7.
import * as cdk from 'aws-cdk-lib';

export class CdkWorkshopStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);

// nothing here!
}
}

8.
exports.handler = async function(event) {
console.log("request:", JSON.stringify(event, undefined, 2));
return {
statusCode: 200,
headers: { "Content-Type": "text/plain" },
body: `Hello, CDK! You've hit ${event.path}\n`
};
};

9.
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';

export class CdkWorkshopStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);

// defines an AWS Lambda resource
const hello = new lambda.Function(this, 'HelloHandler', {
runtime: lambda.Runtime.NODEJS_14_X, // execution environment
code: lambda.Code.fromAsset('lambda'), // code loaded from "lambda" directory
handler: 'hello.handler' // file is "hello", function is "handler"
});
}
}


10.
exports.handler = async function(event) {
console.log("request:", JSON.stringify(event, undefined, 2));
return {
statusCode: 200,
headers: { "Content-Type": "text/plain" },
body: `Good Afternoon, CDK! You've hit ${event.path}\n`
};
};

11.
cdk deploy --hotswap

12.
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as apigw from 'aws-cdk-lib/aws-apigateway';

export class CdkWorkshopStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);

// defines an AWS Lambda resource
const hello = new lambda.Function(this, 'HelloHandler', {
runtime: lambda.Runtime.NODEJS_14_X, // execution environment
code: lambda.Code.fromAsset('lambda'), // code loaded from "lambda" directory
handler: 'hello.handler' // file is "hello", function is "handler"
});

// defines an API Gateway REST API resource backed by our "hello" function.
new apigw.LambdaRestApi(this, 'Endpoint', {
handler: hello
});

}
}

0 comments on commit 82c68a7

Please sign in to comment.