Created
August 15, 2019 09:10
-
-
Save cm-fujii/07806023ce68e0a7d3aa932bfe2d5f54 to your computer and use it in GitHub Desktop.
AWSCDK-MultiStackSample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function handler(event: any) { | |
const id = event.pathParameters.id; | |
return { | |
statusCode: 200, | |
body: JSON.stringify({ | |
env: process.env.SYSTEM_ENV, | |
message: `your request message id is ${id}` | |
}), | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as apigateway from '@aws-cdk/aws-apigateway'; | |
import * as lambda from '@aws-cdk/aws-lambda'; | |
import { Duration } from '@aws-cdk/core'; | |
import cdk = require('@aws-cdk/core'); | |
export class AwscdkMultiStackSampleStack extends cdk.Stack { | |
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
// The code that defines your stack goes here | |
const systemEnv = process.env.SYSTEM_ENV ? process.env.SYSTEM_ENV : 'dev'; | |
// Lambda | |
const sampleLambda = new lambda.Function(this, 'multi-sample-Lambda', { | |
code: lambda.Code.asset('src/lambda'), | |
handler: 'app.handler', | |
runtime: lambda.Runtime.NODEJS_10_X, | |
functionName: `aws-cdk-multi-sample-Lambda-${systemEnv}`, | |
timeout: Duration.seconds(3), | |
environment: { | |
SYSTEM_ENV: systemEnv, | |
} | |
}); | |
// API Gateway | |
const api = new apigateway.RestApi(this, 'multi-sample-api', { | |
restApiName: `AWSCDK-MultiSampleApi-${systemEnv}` | |
}); | |
const integration = new apigateway.LambdaIntegration(sampleLambda, { | |
proxy: true, | |
}); | |
const messageResource = api.root.addResource('message'); | |
const idResource = messageResource.addResource('{id}'); | |
idResource.addMethod('GET', integration); | |
} | |
} | |
const app = new cdk.App(); | |
new AwscdkMultiStackSampleStack(app, 'AWS-CDK-Multi-Stack'); | |
app.synth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
import 'source-map-support/register'; | |
import cdk = require('@aws-cdk/core'); | |
import { AwscdkMultiStackSampleStack } from '../lib/awscdk-multi_stack_sample-stack'; | |
const targetEnv = process.env.SYSTEM_ENV ? process.env.SYSTEM_ENV : 'dev'; | |
const app = new cdk.App(); | |
new AwscdkMultiStackSampleStack(app, `AwscdkMultiStackSampleStack-${targetEnv}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment