diff --git a/docs/src/aws-construct-lib.rst b/docs/src/aws-construct-lib.rst index f2e753a9ab223..212f6d6b2042a 100644 --- a/docs/src/aws-construct-lib.rst +++ b/docs/src/aws-construct-lib.rst @@ -31,7 +31,7 @@ Least-Privilege IAM policies IAM policies are automatically defined based on intent. For example, when subscribing an AWS SNS :py:class:`Topic <@aws-cdk/aws-sns.Topic>` to a AWS Lambda -:py:class:`Function <@aws-cdk/aws-lambda.Lambda>`, the function's IAM permission +:py:class:`Function <@aws-cdk/aws-lambda.Function>`, the function's IAM permission policy will automatically be modified to allow the specific topic to invoke the function. @@ -76,7 +76,7 @@ Many AWS resources emit AWS CloudWatch metrics as part of their normal operation be used to setup :py:mod:`Alarms <@aws-cdk/aws-cloudwatch.Alarm>` or included in :py:mod:`Dashboards <@aws-cdk/aws-cloudwatch.Dashboard>`. :py:mod:`Metric <@aws-cdk/aws-cloudwatch.Metric>` objects for AWS Constructs can be obtained -via ``metricXxx()`` methods. For example, the :py:meth:`metricDuration() <@aws-cdk/aws-lambda.LambdaRef.metricDuration>` +via ``metricXxx()`` methods. For example, the :py:meth:`metricDuration() <@aws-cdk/aws-lambda.FunctionRef.metricDuration>` method reports the execution time of an AWS Lambda function. For more information see the :doc:`refs/_aws-cdk_aws-cloudwatch` documentation. diff --git a/examples/cdk-examples-typescript/chat-app/index.ts b/examples/cdk-examples-typescript/chat-app/index.ts index 9c778fb2b6ea6..4bf4e6b768413 100644 --- a/examples/cdk-examples-typescript/chat-app/index.ts +++ b/examples/cdk-examples-typescript/chat-app/index.ts @@ -76,11 +76,11 @@ interface ChatAppFuncProps { /* * Extend Function as all of the Chat app functions have these common props. */ -class ChatAppFunction extends lambda.Lambda { +class ChatAppFunction extends lambda.Function { constructor(parent: cdk.Construct, name: string, props: ChatAppFuncProps) { super(parent, name, { - code: new lambda.LambdaS3Code(props.bucket, props.zipFile), - runtime: lambda.LambdaRuntime.NodeJS610, + code: new lambda.S3Code(props.bucket, props.zipFile), + runtime: lambda.Runtime.NodeJS610, handler: 'index.handler' }); } diff --git a/packages/@aws-cdk/aws-cloudformation/lib/custom-resource.ts b/packages/@aws-cdk/aws-cloudformation/lib/custom-resource.ts index f2785a82df30c..4083ba16615a8 100644 --- a/packages/@aws-cdk/aws-cloudformation/lib/custom-resource.ts +++ b/packages/@aws-cdk/aws-cloudformation/lib/custom-resource.ts @@ -15,11 +15,11 @@ export interface CustomResourceProps { /** * The Lambda provider that implements this custom resource. * - * We recommend using a SingletonLambda for this. + * We recommend using a lambda.SingletonFunction for this. * * Optional, exactly one of lamdaProvider or topicProvider must be set. */ - lambdaProvider?: lambda.LambdaRef; + lambdaProvider?: lambda.FunctionRef; /** * The SNS Topic for the provider that implements this custom resource. diff --git a/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts b/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts index 12bb7663d26e8..0eab2e20186c2 100644 --- a/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts +++ b/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts @@ -22,13 +22,13 @@ class DemoResource extends cdk.Construct { super(parent, name); const resource = new cloudformation.CustomResource(this, 'Resource', { - lambdaProvider: new lambda.SingletonLambda(this, 'Singleton', { + lambdaProvider: new lambda.SingletonFunction(this, 'Singleton', { uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc', // This makes the demo only work as top-level TypeScript program, but that's fine for now - code: new lambda.LambdaInlineCode(fs.readFileSync('integ.trivial-lambda-provider.py', { encoding: 'utf-8' })), + code: new lambda.InlineCode(fs.readFileSync('integ.trivial-lambda-provider.py', { encoding: 'utf-8' })), handler: 'index.main', timeout: 300, - runtime: lambda.LambdaRuntime.Python27, + runtime: lambda.Runtime.Python27, }), properties: props }); diff --git a/packages/@aws-cdk/aws-cloudformation/test/test.resource.ts b/packages/@aws-cdk/aws-cloudformation/test/test.resource.ts index 24a10f34edd09..a79900bc11800 100644 --- a/packages/@aws-cdk/aws-cloudformation/test/test.resource.ts +++ b/packages/@aws-cdk/aws-cloudformation/test/test.resource.ts @@ -92,10 +92,10 @@ class TestCustomResource extends cdk.Construct { constructor(parent: cdk.Construct, name: string) { super(parent, name); - const singletonLambda = new lambda.SingletonLambda(this, 'Lambda', { + const singletonLambda = new lambda.SingletonFunction(this, 'Lambda', { uuid: 'TestCustomResourceProvider', - code: new lambda.LambdaInlineCode('def hello(): pass'), - runtime: lambda.LambdaRuntime.Python27, + code: new lambda.InlineCode('def hello(): pass'), + runtime: lambda.Runtime.Python27, handler: 'index.hello', timeout: 300, }); diff --git a/packages/@aws-cdk/aws-cloudwatch/README.md b/packages/@aws-cdk/aws-cloudwatch/README.md index abc1de4b205e0..467a4ccab0b12 100644 --- a/packages/@aws-cdk/aws-cloudwatch/README.md +++ b/packages/@aws-cdk/aws-cloudwatch/README.md @@ -8,11 +8,11 @@ attributes. Resources that expose metrics will have functions that look like `metricXxx()` which will return a Metric object, initialized with defaults that make sense. -For example, `Lambda` objects have the `lambda.metricErrors()` method, which +For example, `lambda.Function` objects have the `fn.metricErrors()` method, which represents the amount of errors reported by that Lambda function: ```ts -const errors = lambda.metricErrors(); +const errors = fn.metricErrors(); ``` ### Aggregation @@ -30,7 +30,7 @@ the function or the period), you can do so by passing additional parameters to the metric function call: ```ts -const minuteErrorRate = lambda.metricErrors({ +const minuteErrorRate = fn.metricErrors({ statistic: 'avg', periodSec: 60, label: 'Lambda failure rate' @@ -66,7 +66,7 @@ object, passing the `Metric` object to set the alarm on: ```ts new Alarm(this, 'Alarm', { - metric: lambda.metricErrors(), + metric: fn.metricErrors(), threshold: 100, evaluationPeriods: 2, }); @@ -75,7 +75,7 @@ new Alarm(this, 'Alarm', { Alternatively, you can call `metric.newAlarm()`: ```ts -lambda.metricErrors().newAlarm(this, 'Alarm', { +fn.metricErrors().newAlarm(this, 'Alarm', { threshold: 100, evaluationPeriods: 2, }); diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index cad980e5cd09d..9b48621af3d7a 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -52,5 +52,5 @@ To define CloudWatch event rules for build projects, use one of the `onXxx` meth ```ts const rule = project.onStateChange('BuildStateChange'); -rule.addTarget(lambda); +rule.addTarget(lambdaFunction); ``` diff --git a/packages/@aws-cdk/aws-lambda-codepipeline/lib/pipeline-action.ts b/packages/@aws-cdk/aws-lambda-codepipeline/lib/pipeline-action.ts index e64f8477ce32f..a2088ecf6c308 100644 --- a/packages/@aws-cdk/aws-lambda-codepipeline/lib/pipeline-action.ts +++ b/packages/@aws-cdk/aws-lambda-codepipeline/lib/pipeline-action.ts @@ -9,7 +9,7 @@ export interface PipelineInvokeActionProps { /** * The lambda function to invoke. */ - lambda: lambda.LambdaRef; + lambda: lambda.FunctionRef; /** * String to be used in the event data parameter passed to the Lambda diff --git a/packages/@aws-cdk/aws-lambda-codepipeline/test/integ.pipeline.ts b/packages/@aws-cdk/aws-lambda-codepipeline/test/integ.pipeline.ts index fd132d3b1dfe1..bdc7199b033f2 100644 --- a/packages/@aws-cdk/aws-lambda-codepipeline/test/integ.pipeline.ts +++ b/packages/@aws-cdk/aws-lambda-codepipeline/test/integ.pipeline.ts @@ -20,14 +20,14 @@ new codepipeline.AmazonS3Source(sourceStage, 'Source', { bucketKey: 'key', }); -const lambdaFun = new lambda.Lambda(stack, 'LambdaFun', { - code: new lambda.LambdaInlineCode(` +const lambdaFun = new lambda.Function(stack, 'LambdaFun', { + code: new lambda.InlineCode(` exports.handler = function () { console.log("Hello, world!"); }; `), handler: 'index.handler', - runtime: lambda.LambdaRuntime.NodeJS610, + runtime: lambda.Runtime.NodeJS610, }); const lambdaStage = new codepipeline.Stage(pipeline, 'Lambda'); new lambda_codepipeline.PipelineInvokeAction(lambdaStage, 'Lambda', { diff --git a/packages/@aws-cdk/aws-lambda-codepipeline/test/test.pipeline-action.ts b/packages/@aws-cdk/aws-lambda-codepipeline/test/test.pipeline-action.ts index e2c5ed26a3e2a..b9513222f8827 100644 --- a/packages/@aws-cdk/aws-lambda-codepipeline/test/test.pipeline-action.ts +++ b/packages/@aws-cdk/aws-lambda-codepipeline/test/test.pipeline-action.ts @@ -11,10 +11,10 @@ export = { 'PipelineInvokeAction can be used to invoke lambda functions from a CodePipeline'(test: Test) { const stack = new cdk.Stack(); - const lambdaFun = new lambda.Lambda(stack, 'Function', { - code: new lambda.LambdaInlineCode('bla'), + const lambdaFun = new lambda.Function(stack, 'Function', { + code: new lambda.InlineCode('bla'), handler: 'index.handler', - runtime: lambda.LambdaRuntime.NodeJS43, + runtime: lambda.Runtime.NodeJS43, }); const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); diff --git a/packages/@aws-cdk/aws-lambda/README.md b/packages/@aws-cdk/aws-lambda/README.md index 2ee137544755f..78d22f32f2cc5 100644 --- a/packages/@aws-cdk/aws-lambda/README.md +++ b/packages/@aws-cdk/aws-lambda/README.md @@ -1,28 +1,30 @@ ## AWS Lambda Construct Library -This construct library allows you to define AWS Lambda functions. +This construct library allows you to define AWS Lambda Functions. ```ts -const fn = new Lambda(this, 'MyFunction', { - runtime: LambdaRuntime.NodeJS810, +import lambda = require('@aws-cdk/aws-lambda'); + +const fn = new lambda.Function(this, 'MyFunction', { + runtime: lambda.Runtime.NodeJS810, handler: 'index.handler' - code: LambdaCode.inline('exports.handler = function(event, ctx, cb) { return cb(null, "hi"); }'), + code: lambda.Code.inline('exports.handler = function(event, ctx, cb) { return cb(null, "hi"); }'), }); ``` ### Handler Code -The `LambdaCode` class includes static convenience methods for various types of +The `lambda.Code` class includes static convenience methods for various types of runtime code. - * `LambdaCode.bucket(bucket, key[, objectVersion])` - specify an S3 object that + * `lambda.Code.bucket(bucket, key[, objectVersion])` - specify an S3 object that contains the archive of your runtime code. - * `LambdaCode.inline(code)` - inline the handle code as a string. This is + * `lambda.Code.inline(code)` - inline the handle code as a string. This is limited to 4KB. The class `InlineJavaScriptLambda` can be used to simplify inlining JavaScript functions. - * `LambdaCode.directory(directory)` - specify a directory in the local filesystem + * `lambda.Code.directory(directory)` - specify a directory in the local filesystem which will be zipped and uploaded to S3 before deployment. - * `LambdaCode.file(path)` - specify a file to be used for Lambda code. This can + * `lambda.Code.file(path)` - specify a file to be used for Lambda code. This can be, for example a JAR or a ZIP file, based on the runtime used. The following example shows how to define a Python function and deploy the code from the diff --git a/packages/@aws-cdk/aws-lambda/lib/alias.ts b/packages/@aws-cdk/aws-lambda/lib/alias.ts index ac7c143ec9755..11b07bcb65fc5 100644 --- a/packages/@aws-cdk/aws-lambda/lib/alias.ts +++ b/packages/@aws-cdk/aws-lambda/lib/alias.ts @@ -1,9 +1,9 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); -import { FunctionName, LambdaRef } from './lambda-ref'; -import { LambdaVersion } from './lambda-version'; +import { FunctionName, FunctionRef } from './lambda-ref'; +import { FunctionVersion } from './lambda-version'; import { cloudformation, FunctionArn } from './lambda.generated'; -import { LambdaPermission } from './permission'; +import { Permission } from './permission'; /** * Properties for a new Lambda alias @@ -21,7 +21,7 @@ export interface AliasProps { * * Use lambda.addVersion() to obtain a new lambda version to refer to. */ - version: LambdaVersion; + version: FunctionVersion; /** * Name of this alias @@ -51,7 +51,7 @@ export interface AliasProps { /** * A new alias to a particular version of a Lambda function. */ -export class Alias extends LambdaRef { +export class Alias extends FunctionRef { /** * ARN of this alias * @@ -78,7 +78,7 @@ export class Alias extends LambdaRef { /** * The actual Lambda function object that this Alias is pointing to */ - private readonly underlyingLambda: LambdaRef; + private readonly underlyingLambda: FunctionRef; constructor(parent: cdk.Construct, name: string, props: AliasProps) { super(parent, name); @@ -97,7 +97,7 @@ export class Alias extends LambdaRef { this.functionArn = alias.ref; } - public addPermission(name: string, permission: LambdaPermission) { + public addPermission(name: string, permission: Permission) { // Forward addPermission() to the underlying Lambda object this.underlyingLambda.addPermission(name, permission); } @@ -146,7 +146,7 @@ export interface VersionWeight { /** * The version to route traffic to */ - readonly version: LambdaVersion; + readonly version: FunctionVersion; /** * How much weight to assign to this version (0..1) diff --git a/packages/@aws-cdk/aws-lambda/lib/code.ts b/packages/@aws-cdk/aws-lambda/lib/code.ts index 4a450f926ac69..4eb410263c6f7 100644 --- a/packages/@aws-cdk/aws-lambda/lib/code.ts +++ b/packages/@aws-cdk/aws-lambda/lib/code.ts @@ -1,9 +1,9 @@ import assets = require('@aws-cdk/assets'); import s3 = require('@aws-cdk/aws-s3'); -import { Lambda } from './lambda'; +import { Function as Func } from './lambda'; import { cloudformation } from './lambda.generated'; -export abstract class LambdaCode { +export abstract class Code { /** * @returns `LambdaS3Code` associated with the specified S3 object. * @param bucket The S3 bucket @@ -11,7 +11,7 @@ export abstract class LambdaCode { * @param objectVersion Optional S3 object version */ public static bucket(bucket: s3.BucketRef, key: string, objectVersion?: string) { - return new LambdaS3Code(bucket, key, objectVersion); + return new S3Code(bucket, key, objectVersion); } /** @@ -19,7 +19,7 @@ export abstract class LambdaCode { * @param code The actual handler code (limited to 4KiB) */ public static inline(code: string) { - return new LambdaInlineCode(code); + return new InlineCode(code); } /** @@ -28,7 +28,7 @@ export abstract class LambdaCode { * @param directoryToZip The directory to zip */ public static directory(directoryToZip: string) { - return new LambdaAssetCode(directoryToZip, assets.AssetPackaging.ZipDirectory); + return new AssetCode(directoryToZip, assets.AssetPackaging.ZipDirectory); } /** @@ -36,7 +36,7 @@ export abstract class LambdaCode { * @param filePath The file path */ public static file(filePath: string) { - return new LambdaAssetCode(filePath, assets.AssetPackaging.File); + return new AssetCode(filePath, assets.AssetPackaging.File); } /** @@ -49,7 +49,7 @@ export abstract class LambdaCode { * Called when the lambda is initialized to allow this object to * bind to the stack, add resources and have fun. */ - public bind(_lambda: Lambda) { + public bind(_lambda: Func) { return; } } @@ -57,7 +57,7 @@ export abstract class LambdaCode { /** * Lambda code from an S3 archive. */ -export class LambdaS3Code extends LambdaCode { +export class S3Code extends Code { private bucketName: s3.BucketName; constructor(bucket: s3.BucketRef, private key: string, private objectVersion?: string) { @@ -82,7 +82,7 @@ export class LambdaS3Code extends LambdaCode { /** * Lambda code from an inline string (limited to 4KiB). */ -export class LambdaInlineCode extends LambdaCode { +export class InlineCode extends Code { constructor(private code: string) { super(); @@ -91,7 +91,7 @@ export class LambdaInlineCode extends LambdaCode { } } - public bind(lambda: Lambda) { + public bind(lambda: Func) { if (!lambda.runtime.supportsInlineCode) { throw new Error(`Inline source not allowed for ${lambda.runtime.name}`); } @@ -107,7 +107,7 @@ export class LambdaInlineCode extends LambdaCode { /** * Lambda code from a local directory. */ -export class LambdaAssetCode extends LambdaCode { +export class AssetCode extends Code { private asset?: assets.Asset; /** @@ -120,7 +120,7 @@ export class LambdaAssetCode extends LambdaCode { super(); } - public bind(lambda: Lambda) { + public bind(lambda: Func) { this.asset = new assets.Asset(lambda, 'Code', { path: this.path, packaging: this.packaging diff --git a/packages/@aws-cdk/aws-lambda/lib/inline.ts b/packages/@aws-cdk/aws-lambda/lib/inline.ts index 2c841c6cc6660..f58b30c313c13 100644 --- a/packages/@aws-cdk/aws-lambda/lib/inline.ts +++ b/packages/@aws-cdk/aws-lambda/lib/inline.ts @@ -1,7 +1,7 @@ import { Construct } from '@aws-cdk/cdk'; -import { LambdaInlineCode } from './code'; -import { Lambda } from './lambda'; -import { InlinableJavascriptLambdaRuntime, LambdaRuntime } from './runtime'; +import { InlineCode } from './code'; +import { Function } from './lambda'; +import { InlinableJavaScriptRuntime, Runtime } from './runtime'; /** * Defines the handler code for an inline JavaScript lambda function. @@ -68,7 +68,7 @@ export interface InlineJavaScriptLambdaProps { * * @default NodeJS810 */ - runtime?: InlinableJavascriptLambdaRuntime; + runtime?: InlinableJavaScriptRuntime; /** * A name for the function. If you don't specify a name, AWS CloudFormation @@ -105,10 +105,10 @@ export interface InlineJavaScriptLambdaProps { * This will define a node.js 6.10 function with the provided function has * the handler code. */ -export class InlineJavaScriptLambda extends Lambda { +export class InlineJavaScriptFunction extends Function { constructor(parent: Construct, name: string, props: InlineJavaScriptLambdaProps) { - const code = new LambdaInlineCode(renderCode(props.handler)); - const runtime: InlinableJavascriptLambdaRuntime = props.runtime || LambdaRuntime.NodeJS610; + const code = new InlineCode(renderCode(props.handler)); + const runtime: InlinableJavaScriptRuntime = props.runtime || Runtime.NodeJS610; const handler = 'index.handler'; const timeout = props.timeout || 30; super(parent, name, { diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts b/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts index 8eafd2b30d4da..79402f1a4ff6f 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts @@ -4,12 +4,12 @@ import iam = require('@aws-cdk/aws-iam'); import logs = require('@aws-cdk/aws-logs'); import cdk = require('@aws-cdk/cdk'); import { cloudformation, FunctionArn } from './lambda.generated'; -import { LambdaPermission } from './permission'; +import { Permission } from './permission'; /** * Represents a Lambda function defined outside of this stack. */ -export interface LambdaRefProps { +export interface FunctionRefProps { /** * The ARN of the Lambda function. * Format: arn::lambda:::function: @@ -23,7 +23,7 @@ export interface LambdaRefProps { role?: iam.Role; } -export abstract class LambdaRef extends cdk.Construct implements events.IEventRuleTarget, logs.ILogSubscriptionDestination { +export abstract class FunctionRef extends cdk.Construct implements events.IEventRuleTarget, logs.ILogSubscriptionDestination { /** * Creates a Lambda function object which represents a function not defined * within this stack. @@ -35,7 +35,7 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu * @param ref A reference to a Lambda function. Can be created manually (see * example above) or obtained through a call to `lambda.export()`. */ - public static import(parent: cdk.Construct, name: string, ref: LambdaRefProps): LambdaRef { + public static import(parent: cdk.Construct, name: string, ref: FunctionRefProps): FunctionRef { return new LambdaRefImport(parent, name, ref); } @@ -55,7 +55,7 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu * @default sum over 5 minutes */ public static metricAllErrors(props?: cloudwatch.MetricCustomization): cloudwatch.Metric { - return LambdaRef.metricAll('Errors', { statistic: 'sum', ...props }); + return FunctionRef.metricAll('Errors', { statistic: 'sum', ...props }); } /** @@ -64,7 +64,7 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu * @default average over 5 minutes */ public static metricAllDuration(props?: cloudwatch.MetricCustomization): cloudwatch.Metric { - return LambdaRef.metricAll('Duration', props); + return FunctionRef.metricAll('Duration', props); } /** @@ -73,7 +73,7 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu * @default sum over 5 minutes */ public static metricAllInvocations(props?: cloudwatch.MetricCustomization): cloudwatch.Metric { - return LambdaRef.metricAll('Invocations', { statistic: 'sum', ...props }); + return FunctionRef.metricAll('Invocations', { statistic: 'sum', ...props }); } /** @@ -82,7 +82,7 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu * @default sum over 5 minutes */ public static metricAllThrottles(props?: cloudwatch.MetricCustomization): cloudwatch.Metric { - return LambdaRef.metricAll('Throttles', { statistic: 'sum', ...props }); + return FunctionRef.metricAll('Throttles', { statistic: 'sum', ...props }); } /** @@ -97,7 +97,7 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu // probably what you're interested in if you're looking at this metric // (Load spikes may lead to concurrent execution errors that would // otherwise not be visible in the avg) - return LambdaRef.metricAll('ConcurrentExecutions', { statistic: 'max', ...props }); + return FunctionRef.metricAll('ConcurrentExecutions', { statistic: 'max', ...props }); } /** @@ -106,7 +106,7 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu * @default max over 5 minutes */ public static metricAllUnreservedConcurrentExecutions(props?: cloudwatch.MetricCustomization): cloudwatch.Metric { - return LambdaRef.metricAll('UnreservedConcurrentExecutions', { statistic: 'max', ...props }); + return FunctionRef.metricAll('UnreservedConcurrentExecutions', { statistic: 'max', ...props }); } /** @@ -146,7 +146,7 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu * Adds a permission to the Lambda resource policy. * @param name A name for the permission construct */ - public addPermission(name: string, permission: LambdaPermission) { + public addPermission(name: string, permission: Permission) { if (!this.canCreatePermissions) { // FIXME: Report metadata return; @@ -261,7 +261,7 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu /** * Export this Function (without the role) */ - public export(): LambdaRefProps { + public export(): FunctionRefProps { return { functionArn: new cdk.Output(this, 'FunctionArn', { value: this.functionArn }).makeImportValue(), }; @@ -287,14 +287,14 @@ export abstract class LambdaRef extends cdk.Construct implements events.IEventRu } } -class LambdaRefImport extends LambdaRef { +class LambdaRefImport extends FunctionRef { public readonly functionName: FunctionName; public readonly functionArn: FunctionArn; public readonly role?: iam.Role; protected readonly canCreatePermissions = false; - constructor(parent: cdk.Construct, name: string, props: LambdaRefProps) { + constructor(parent: cdk.Construct, name: string, props: FunctionRefProps) { super(parent, name); this.functionArn = props.functionArn; diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts index 04507ca33da28..fc1f82c0bb1b8 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts @@ -1,11 +1,11 @@ import { Construct } from '@aws-cdk/cdk'; -import { LambdaRef } from './lambda-ref'; +import { FunctionRef } from './lambda-ref'; import { cloudformation, Version } from './lambda.generated'; /** * Properties for a new Lambda version */ -export interface LambdaVersionProps { +export interface FunctionVersionProps { /** * SHA256 of the version of the Lambda source code * @@ -25,7 +25,7 @@ export interface LambdaVersionProps { /** * Function to get the value of */ - lambda: LambdaRef; + lambda: FunctionRef; } /** @@ -44,7 +44,7 @@ export interface LambdaVersionProps { * the right deployment, specify the `codeSha256` property while * creating the `Version. */ -export class LambdaVersion extends Construct { +export class FunctionVersion extends Construct { /** * The most recently deployed version of this function. */ @@ -53,9 +53,9 @@ export class LambdaVersion extends Construct { /** * Lambda object this version is associated with */ - public readonly lambda: LambdaRef; + public readonly lambda: FunctionRef; - constructor(parent: Construct, name: string, props: LambdaVersionProps) { + constructor(parent: Construct, name: string, props: FunctionVersionProps) { super(parent, name); const version = new cloudformation.VersionResource(this, 'Resource', { diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda.ts b/packages/@aws-cdk/aws-lambda/lib/lambda.ts index c1f389bdda2b4..620ffe1ceff55 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda.ts @@ -1,18 +1,18 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); -import { LambdaCode } from './code'; -import { FunctionName, LambdaRef } from './lambda-ref'; -import { LambdaVersion } from './lambda-version'; +import { Code } from './code'; +import { FunctionName, FunctionRef } from './lambda-ref'; +import { FunctionVersion } from './lambda-version'; import { cloudformation, FunctionArn } from './lambda.generated'; -import { LambdaRuntime } from './runtime'; +import { Runtime } from './runtime'; -export interface LambdaProps { +export interface FunctionProps { /** * The source code of your Lambda function. You can point to a file in an * Amazon Simple Storage Service (Amazon S3) bucket or specify your source * code as inline text. */ - code: LambdaCode; + code: Code; /** * A description of the function. @@ -52,7 +52,7 @@ export interface LambdaProps { * For valid values, see the Runtime property in the AWS Lambda Developer * Guide. */ - runtime: LambdaRuntime; + runtime: Runtime; /** * A name for the function. If you don't specify a name, AWS CloudFormation @@ -102,7 +102,7 @@ export interface LambdaProps { * This construct does not yet reproduce all features from the underlying resource * library. */ -export class Lambda extends LambdaRef { +export class Function extends FunctionRef { /** * Name of this function */ @@ -121,7 +121,7 @@ export class Lambda extends LambdaRef { /** * The runtime configured for this lambda. */ - public readonly runtime: LambdaRuntime; + public readonly runtime: Runtime; /** * The name of the handler configured for this lambda. @@ -135,7 +135,7 @@ export class Lambda extends LambdaRef { */ private readonly environment?: { [key: string]: any }; - constructor(parent: cdk.Construct, name: string, props: LambdaProps) { + constructor(parent: cdk.Construct, name: string, props: FunctionProps) { super(parent, name); this.environment = props.environment || { }; @@ -209,8 +209,8 @@ export class Lambda extends LambdaRef { * @param description A description for this version. * @returns A new Version object. */ - public addVersion(name: string, codeSha256?: string, description?: string): LambdaVersion { - return new LambdaVersion(this, 'Version' + name, { + public addVersion(name: string, codeSha256?: string, description?: string): FunctionVersion { + return new FunctionVersion(this, 'Version' + name, { lambda: this, codeSha256, description, diff --git a/packages/@aws-cdk/aws-lambda/lib/permission.ts b/packages/@aws-cdk/aws-lambda/lib/permission.ts index 95984b97a1f75..d4b6215638832 100644 --- a/packages/@aws-cdk/aws-lambda/lib/permission.ts +++ b/packages/@aws-cdk/aws-lambda/lib/permission.ts @@ -4,7 +4,7 @@ import { Arn, PolicyPrincipal } from '@aws-cdk/cdk'; * Represents a permission statement that can be added to a Lambda's resource policy * via the `addToResourcePolicy` method. */ -export interface LambdaPermission { +export interface Permission { /** * The Lambda actions that you want to allow in this statement. For example, * you can specify lambda:CreateFunction to specify a certain action, or use diff --git a/packages/@aws-cdk/aws-lambda/lib/runtime.ts b/packages/@aws-cdk/aws-lambda/lib/runtime.ts index 7e8ec83e9deb6..4163c6bc608dc 100644 --- a/packages/@aws-cdk/aws-lambda/lib/runtime.ts +++ b/packages/@aws-cdk/aws-lambda/lib/runtime.ts @@ -9,23 +9,23 @@ export interface LambdaRuntimeProps { /** * Lambda function runtime environment. */ -export class LambdaRuntime implements InlinableLambdaRuntime, InlinableJavascriptLambdaRuntime { - public static readonly NodeJS = new LambdaRuntime('nodejs', { supportsInlineCode: true }) as InlinableJavascriptLambdaRuntime; +export class Runtime implements InlinableRuntime, InlinableJavaScriptRuntime { + public static readonly NodeJS = new Runtime('nodejs', { supportsInlineCode: true }) as InlinableJavaScriptRuntime; // Using ``as InlinableLambdaRuntime`` because that class cannot be defined just yet - public static readonly NodeJS43 = new LambdaRuntime('nodejs4.3', { supportsInlineCode: true }) as InlinableJavascriptLambdaRuntime; - public static readonly NodeJS43Edge = new LambdaRuntime('nodejs4.3-edge'); + public static readonly NodeJS43 = new Runtime('nodejs4.3', { supportsInlineCode: true }) as InlinableJavaScriptRuntime; + public static readonly NodeJS43Edge = new Runtime('nodejs4.3-edge'); // Using ``as InlinableLambdaRuntime`` because that class cannot be defined just yet - public static readonly NodeJS610 = new LambdaRuntime('nodejs6.10', { supportsInlineCode: true }) as InlinableJavascriptLambdaRuntime; - public static readonly NodeJS810 = new LambdaRuntime('nodejs8.10'); - public static readonly Java8 = new LambdaRuntime('java8'); + public static readonly NodeJS610 = new Runtime('nodejs6.10', { supportsInlineCode: true }) as InlinableJavaScriptRuntime; + public static readonly NodeJS810 = new Runtime('nodejs8.10'); + public static readonly Java8 = new Runtime('java8'); // Using ``as InlinableLambdaRuntime`` because that class cannot be defined just yet - public static readonly Python27 = new LambdaRuntime('python2.7', { supportsInlineCode: true }) as InlinableLambdaRuntime; + public static readonly Python27 = new Runtime('python2.7', { supportsInlineCode: true }) as InlinableRuntime; // Using ``as InlinableLambdaRuntime`` because that class cannot be defined just yet - public static readonly Python36 = new LambdaRuntime('python3.6', { supportsInlineCode: true }) as InlinableLambdaRuntime; - public static readonly DotNetCore1 = new LambdaRuntime('dotnetcore1.0'); - public static readonly DotNetCore2 = new LambdaRuntime('dotnetcore2.0'); - public static readonly DotNetCore21 = new LambdaRuntime('dotnetcore2.1'); - public static readonly Go1x = new LambdaRuntime('go1.x'); + public static readonly Python36 = new Runtime('python3.6', { supportsInlineCode: true }) as InlinableRuntime; + public static readonly DotNetCore1 = new Runtime('dotnetcore1.0'); + public static readonly DotNetCore2 = new Runtime('dotnetcore2.0'); + public static readonly DotNetCore21 = new Runtime('dotnetcore2.1'); + public static readonly Go1x = new Runtime('go1.x'); /** The name of this runtime, as expected by the Lambda resource. */ public readonly name: string; @@ -46,7 +46,7 @@ export class LambdaRuntime implements InlinableLambdaRuntime, InlinableJavascrip * A ``LambdaRuntime`` that can be used in conjunction with the ``ZipFile`` * property of the ``AWS::Lambda::Function`` resource. */ -export interface InlinableLambdaRuntime { +export interface InlinableRuntime { readonly name: string; readonly supportsInlineCode: boolean; } @@ -55,4 +55,4 @@ export interface InlinableLambdaRuntime { * A ``LambdaRuntime`` that can be used for inlining JavaScript. */ // tslint:disable-next-line:no-empty-interface this is a marker to allow type-safe declarations -export interface InlinableJavascriptLambdaRuntime extends InlinableLambdaRuntime {} +export interface InlinableJavaScriptRuntime extends InlinableRuntime {} diff --git a/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts b/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts index 6eec310226037..226f69b733ddf 100644 --- a/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts +++ b/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts @@ -1,14 +1,14 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); -import { Lambda, LambdaProps } from './lambda'; -import { FunctionName, LambdaRef } from './lambda-ref'; +import { Function, FunctionProps } from './lambda'; +import { FunctionName, FunctionRef } from './lambda-ref'; import { FunctionArn } from './lambda.generated'; -import { LambdaPermission } from './permission'; +import { Permission } from './permission'; /** * Properties for a newly created singleton Lambda */ -export interface SingletonLambdaProps extends LambdaProps { +export interface SingletonFunctionProps extends FunctionProps { /** * A unique identifier to identify this lambda * @@ -35,14 +35,14 @@ export interface SingletonLambdaProps extends LambdaProps { * The lambda is identified using the value of 'uuid'. Run 'uuidgen' * for every SingletonLambda you create. */ -export class SingletonLambda extends LambdaRef { +export class SingletonFunction extends FunctionRef { public readonly functionName: FunctionName; public readonly functionArn: FunctionArn; public readonly role?: iam.Role | undefined; protected readonly canCreatePermissions: boolean; - private lambdaFunction: LambdaRef; + private lambdaFunction: FunctionRef; - constructor(parent: cdk.Construct, name: string, props: SingletonLambdaProps) { + constructor(parent: cdk.Construct, name: string, props: SingletonFunctionProps) { super(parent, name); this.lambdaFunction = this.ensureLambda(props); @@ -54,20 +54,20 @@ export class SingletonLambda extends LambdaRef { this.canCreatePermissions = true; // Doesn't matter, addPermission is overriden anyway } - public addPermission(name: string, permission: LambdaPermission) { + public addPermission(name: string, permission: Permission) { return this.lambdaFunction.addPermission(name, permission); } - private ensureLambda(props: SingletonLambdaProps): LambdaRef { + private ensureLambda(props: SingletonFunctionProps): FunctionRef { const constructName = (props.lambdaPurpose || 'SingletonLambda') + slugify(props.uuid); const stack = cdk.Stack.find(this); const existing = stack.tryFindChild(constructName); if (existing) { // Just assume this is true - return existing as LambdaRef; + return existing as FunctionRef; } - return new Lambda(stack, constructName, props); + return new Function(stack, constructName, props); } } diff --git a/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts b/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts index cf74288ca61b7..96ce0a6d10824 100644 --- a/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts +++ b/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts @@ -1,16 +1,16 @@ import cdk = require('@aws-cdk/cdk'); import path = require('path'); -import { Lambda, LambdaCode, LambdaRuntime } from '../lib'; +import lambda = require('../lib'); class TestStack extends cdk.Stack { constructor(parent: cdk.App, id: string) { super(parent, id); /// !show - new Lambda(this, 'MyLambda', { - code: LambdaCode.file(path.join(__dirname, 'handler.zip')), + new lambda.Function(this, 'MyLambda', { + code: lambda.Code.file(path.join(__dirname, 'handler.zip')), handler: 'index.main', - runtime: LambdaRuntime.Python36 + runtime: lambda.Runtime.Python36 }); /// !hide } diff --git a/packages/@aws-cdk/aws-lambda/test/integ.assets.lit.ts b/packages/@aws-cdk/aws-lambda/test/integ.assets.lit.ts index 2ae4005806feb..f8051aef52055 100644 --- a/packages/@aws-cdk/aws-lambda/test/integ.assets.lit.ts +++ b/packages/@aws-cdk/aws-lambda/test/integ.assets.lit.ts @@ -1,16 +1,16 @@ import cdk = require('@aws-cdk/cdk'); import path = require('path'); -import { Lambda, LambdaCode, LambdaRuntime } from '../lib'; +import lambda = require('../lib'); class TestStack extends cdk.Stack { constructor(parent: cdk.App, id: string) { super(parent, id); /// !show - new Lambda(this, 'MyLambda', { - code: LambdaCode.directory(path.join(__dirname, 'my-lambda-handler')), + new lambda.Function(this, 'MyLambda', { + code: lambda.Code.directory(path.join(__dirname, 'my-lambda-handler')), handler: 'index.main', - runtime: LambdaRuntime.Python36 + runtime: lambda.Runtime.Python36 }); /// !hide } diff --git a/packages/@aws-cdk/aws-lambda/test/integ.inline.ts b/packages/@aws-cdk/aws-lambda/test/integ.inline.ts index 55a252170fef6..7117b303a8193 100644 --- a/packages/@aws-cdk/aws-lambda/test/integ.inline.ts +++ b/packages/@aws-cdk/aws-lambda/test/integ.inline.ts @@ -1,6 +1,6 @@ import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); -import { InlineJavaScriptLambda } from '../lib/inline'; +import lambda = require('../lib'); const app = new cdk.App(process.argv); @@ -8,7 +8,7 @@ const stack = new cdk.Stack(app, 'aws-cdk-lambda-2'); const bucket = new s3.Bucket(stack, 'MyBucket'); -const lambda = new InlineJavaScriptLambda(stack, 'MyLambda', { +const fn = new lambda.InlineJavaScriptFunction(stack, 'MyLambda', { environment: { BUCKET_NAME: bucket.bucketName }, @@ -34,6 +34,6 @@ const lambda = new InlineJavaScriptLambda(stack, 'MyLambda', { } }); -bucket.grantReadWrite(lambda.role); +bucket.grantReadWrite(fn.role); process.stdout.write(app.run()); diff --git a/packages/@aws-cdk/aws-lambda/test/integ.lambda.ts b/packages/@aws-cdk/aws-lambda/test/integ.lambda.ts index eab9db265bf42..3ca2aac0bc342 100644 --- a/packages/@aws-cdk/aws-lambda/test/integ.lambda.ts +++ b/packages/@aws-cdk/aws-lambda/test/integ.lambda.ts @@ -1,21 +1,21 @@ -import { App, PolicyStatement, Stack } from '@aws-cdk/cdk'; -import { Alias, Lambda, LambdaInlineCode, LambdaRuntime } from '../lib'; +import cdk = require('@aws-cdk/cdk'); +import lambda = require('../lib'); -const app = new App(process.argv); +const app = new cdk.App(process.argv); -const stack = new Stack(app, 'aws-cdk-lambda-1'); +const stack = new cdk.Stack(app, 'aws-cdk-lambda-1'); -const fn = new Lambda(stack, 'MyLambda', { - code: new LambdaInlineCode('foo'), +const fn = new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: LambdaRuntime.NodeJS610, + runtime: lambda.Runtime.NodeJS610, }); -fn.addToRolePolicy(new PolicyStatement().addResource('*').addAction('*')); +fn.addToRolePolicy(new cdk.PolicyStatement().addResource('*').addAction('*')); const version = fn.addVersion('1'); -new Alias(stack, 'Alias', { +new lambda.Alias(stack, 'Alias', { aliasName: 'prod', version, }); diff --git a/packages/@aws-cdk/aws-lambda/test/test.alias.ts b/packages/@aws-cdk/aws-lambda/test/test.alias.ts index 93babd32dc244..16d76502e0966 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.alias.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.alias.ts @@ -1,20 +1,20 @@ import { beASupersetOfTemplate, expect, haveResource } from '@aws-cdk/assert'; import { AccountPrincipal, resolve, Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; -import { Alias, Lambda, LambdaInlineCode, LambdaRuntime } from '../lib'; +import lambda = require('../lib'); export = { 'version and aliases'(test: Test): void { const stack = new Stack(); - const lambda = new Lambda(stack, 'MyLambda', { - code: new LambdaInlineCode('hello()'), + const fn = new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: LambdaRuntime.NodeJS610, + runtime: lambda.Runtime.NodeJS610, }); - const version = lambda.addVersion('1'); + const version = fn.addVersion('1'); - new Alias(stack, 'Alias', { + new lambda.Alias(stack, 'Alias', { aliasName: 'prod', version, }); @@ -42,16 +42,16 @@ export = { 'can add additional versions to alias'(test: Test) { const stack = new Stack(); - const lambda = new Lambda(stack, 'MyLambda', { - code: new LambdaInlineCode('hello()'), + const fn = new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: LambdaRuntime.NodeJS610, + runtime: lambda.Runtime.NodeJS610, }); - const version1 = lambda.addVersion('1'); - const version2 = lambda.addVersion('2'); + const version1 = fn.addVersion('1'); + const version2 = fn.addVersion('2'); - new Alias(stack, 'Alias', { + new lambda.Alias(stack, 'Alias', { aliasName: 'prod', version: version1, additionalVersions: [{ version: version2, weight: 0.1 }] @@ -75,17 +75,17 @@ export = { 'sanity checks on version weights'(test: Test) { const stack = new Stack(); - const lambda = new Lambda(stack, 'MyLambda', { - code: new LambdaInlineCode('hello()'), + const fn = new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: LambdaRuntime.NodeJS610, + runtime: lambda.Runtime.NodeJS610, }); - const version = lambda.addVersion('1'); + const version = fn.addVersion('1'); // WHEN: Individual weight too high test.throws(() => { - new Alias(stack, 'Alias1', { + new lambda.Alias(stack, 'Alias1', { aliasName: 'prod', version, additionalVersions: [{ version, weight: 5 }] }); @@ -93,7 +93,7 @@ export = { // WHEN: Sum too high test.throws(() => { - new Alias(stack, 'Alias2', { + new lambda.Alias(stack, 'Alias2', { aliasName: 'prod', version, additionalVersions: [{ version, weight: 0.5 }, { version, weight: 0.6 }] }); @@ -106,14 +106,14 @@ export = { const stack = new Stack(); // GIVEN - const lambda = new Lambda(stack, 'MyLambda', { - code: new LambdaInlineCode('hello()'), + const fn = new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: LambdaRuntime.NodeJS610, + runtime: lambda.Runtime.NodeJS610, }); - const version = lambda.addVersion('1'); - const alias = new Alias(stack, 'Alias', { aliasName: 'prod', version }); + const version = fn.addVersion('1'); + const alias = new lambda.Alias(stack, 'Alias', { aliasName: 'prod', version }); // WHEN alias.addPermission('Perm', { @@ -122,7 +122,7 @@ export = { // THEN expect(stack).to(haveResource('AWS::Lambda::Permission', { - FunctionName: resolve(lambda.functionName), + FunctionName: resolve(fn.functionName), Principal: "123456" })); diff --git a/packages/@aws-cdk/aws-lambda/test/test.inline.ts b/packages/@aws-cdk/aws-lambda/test/test.inline.ts index 077fff6e65fad..508dfcd894622 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.inline.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.inline.ts @@ -4,14 +4,14 @@ import cdk = require('@aws-cdk/cdk'); import fs = require('fs'); import { Test } from 'nodeunit'; import path = require('path'); -import { InlineJavaScriptLambda } from '../lib'; +import { InlineJavaScriptFunction } from '../lib'; export = { 'inline node lambda allows plugging in javascript functions as handlers'(test: Test) { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); - const lambda = new InlineJavaScriptLambda(stack, 'MyLambda', { + const lambda = new InlineJavaScriptFunction(stack, 'MyLambda', { environment: { BUCKET_NAME: bucket.bucketName }, diff --git a/packages/@aws-cdk/aws-lambda/test/test.lambda.ts b/packages/@aws-cdk/aws-lambda/test/test.lambda.ts index 1edd36e3816a9..095a3ecd08d0e 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.lambda.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.lambda.ts @@ -4,7 +4,7 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; import path = require('path'); -import { Lambda, LambdaCode, LambdaInlineCode, LambdaRef, LambdaRuntime } from '../lib'; +import lambda = require('../lib'); // tslint:disable:object-literal-key-quotes @@ -12,10 +12,10 @@ export = { 'default function'(test: Test) { const stack = new cdk.Stack(); - new Lambda(stack, 'MyLambda', { - code: new LambdaInlineCode('foo'), + new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: LambdaRuntime.NodeJS610, + runtime: lambda.Runtime.NodeJS610, }); expect(stack).toMatch({ Resources: @@ -46,10 +46,10 @@ export = { 'adds policy permissions'(test: Test) { const stack = new cdk.Stack(); - new Lambda(stack, 'MyLambda', { - code: new LambdaInlineCode('foo'), + new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: LambdaRuntime.NodeJS610, + runtime: lambda.Runtime.NodeJS610, initialPolicy: [new cdk.PolicyStatement().addAction("*").addResource("*")] }); expect(stack).toMatch({ Resources: @@ -101,10 +101,10 @@ export = { 'fails if inline code is used for an invalid runtime'(test: Test) { const stack = new cdk.Stack(); - test.throws(() => new Lambda(stack, 'MyLambda', { - code: new LambdaInlineCode('foo'), + test.throws(() => new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: LambdaRuntime.DotNetCore2 + runtime: lambda.Runtime.DotNetCore2 })); test.done(); }, @@ -112,9 +112,9 @@ export = { 'addToResourcePolicy': { 'can be used to add permissions to the Lambda function'(test: Test) { const stack = new cdk.Stack(); - const lambda = newTestLambda(stack); + const fn = newTestLambda(stack); - lambda.addPermission('S3Permission', { + fn.addPermission('S3Permission', { action: 'lambda:*', principal: new cdk.ServicePrincipal('s3.amazonaws.com'), sourceAccount: new cdk.AwsAccountId(), @@ -184,13 +184,13 @@ export = { 'fails if the principal is not a service or account principals'(test: Test) { const stack = new cdk.Stack(); - const lambda = newTestLambda(stack); + const fn = newTestLambda(stack); - test.throws(() => lambda.addPermission('F1', { principal: new cdk.ArnPrincipal('just:arn') }), + test.throws(() => fn.addPermission('F1', { principal: new cdk.ArnPrincipal('just:arn') }), /Invalid principal type for Lambda permission statement/); - lambda.addPermission('S1', { principal: new cdk.ServicePrincipal('my-service') }); - lambda.addPermission('S2', { principal: new cdk.AccountPrincipal('account') }); + fn.addPermission('S1', { principal: new cdk.ServicePrincipal('my-service') }); + fn.addPermission('S2', { principal: new cdk.AccountPrincipal('account') }); test.done(); }, @@ -204,9 +204,9 @@ export = { role.addToPolicy(new cdk.PolicyStatement().addAction('confirm:itsthesame')); // WHEN - const fn = new Lambda(stack, 'Function', { - code: new LambdaInlineCode('test'), - runtime: LambdaRuntime.Python36, + const fn = new lambda.Function(stack, 'Function', { + code: new lambda.InlineCode('test'), + runtime: lambda.Runtime.Python36, handler: 'index.test', role, initialPolicy: [ @@ -236,11 +236,11 @@ export = { // GIVEN const stack1 = new cdk.Stack(); const stack2 = new cdk.Stack(); - const lambda = newTestLambda(stack1); + const fn = newTestLambda(stack1); // WHEN - const props = lambda.export(); - const imported = LambdaRef.import(stack2, 'Imported', props); + const props = fn.export(); + const imported = lambda.FunctionRef.import(stack2, 'Imported', props); // Can call addPermission() but it won't do anything imported.addPermission('Hello', { @@ -254,11 +254,11 @@ export = { 'Lambda can serve as EventRule target, permission gets added'(test: Test) { // GIVEN const stack = new cdk.Stack(); - const lambda = newTestLambda(stack); + const fn = newTestLambda(stack); const rule = new events.EventRule(stack, 'Rule'); // WHEN - rule.addTarget(lambda); + rule.addTarget(fn); // THEN const lambdaId = "MyLambdaCCE802FB"; @@ -284,10 +284,10 @@ export = { 'Lambda code can be read from a local directory via an asset'(test: Test) { // GIVEN const stack = new cdk.Stack(); - new Lambda(stack, 'MyLambda', { - code: LambdaCode.directory(path.join(__dirname, 'my-lambda-handler')), + new lambda.Function(stack, 'MyLambda', { + code: lambda.Code.directory(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', - runtime: LambdaRuntime.Python36 + runtime: lambda.Runtime.Python36 }); // THEN @@ -315,9 +315,9 @@ export = { }; function newTestLambda(parent: cdk.Construct) { - return new Lambda(parent, 'MyLambda', { - code: new LambdaInlineCode('foo'), + return new lambda.Function(parent, 'MyLambda', { + code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: LambdaRuntime.Python27 + runtime: lambda.Runtime.Python27 }); } diff --git a/packages/@aws-cdk/aws-lambda/test/test.singleton-lambda.ts b/packages/@aws-cdk/aws-lambda/test/test.singleton-lambda.ts index 51f9c09f65fc3..18a706f10982b 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.singleton-lambda.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.singleton-lambda.ts @@ -10,10 +10,10 @@ export = { // WHEN for (let i = 0; i < 5; i++) { - new lambda.SingletonLambda(stack, `Singleton${i}`, { + new lambda.SingletonFunction(stack, `Singleton${i}`, { uuid: '84c0de93-353f-4217-9b0b-45b6c993251a', - code: new lambda.LambdaInlineCode('def hello(): pass'), - runtime: lambda.LambdaRuntime.Python27, + code: new lambda.InlineCode('def hello(): pass'), + runtime: lambda.Runtime.Python27, handler: 'index.hello', timeout: 300, }); diff --git a/packages/@aws-cdk/aws-lambda/test/test.subscriptiondestination.ts b/packages/@aws-cdk/aws-lambda/test/test.subscriptiondestination.ts index 1b85ae9fafae3..fd6d44dd80179 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.subscriptiondestination.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.subscriptiondestination.ts @@ -2,23 +2,23 @@ import { expect, haveResource } from '@aws-cdk/assert'; import logs = require('@aws-cdk/aws-logs'); import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; -import { Lambda, LambdaInlineCode, LambdaRuntime } from '../lib'; +import lambda = require('../lib'); export = { 'lambda can be used as metric subscription destination'(test: Test) { // GIVEN const stack = new cdk.Stack(); - const lambda = new Lambda(stack, 'MyLambda', { - code: new LambdaInlineCode('foo'), + const fn = new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: LambdaRuntime.NodeJS610, + runtime: lambda.Runtime.NodeJS610, }); const logGroup = new logs.LogGroup(stack, 'LogGroup'); // WHEN new logs.SubscriptionFilter(stack, 'Subscription', { logGroup, - destination: lambda, + destination: fn, filterPattern: logs.FilterPattern.allEvents() }); diff --git a/packages/@aws-cdk/aws-logs/README.md b/packages/@aws-cdk/aws-logs/README.md index 65d69e6dd20d2..1f223bc6b26de 100644 --- a/packages/@aws-cdk/aws-logs/README.md +++ b/packages/@aws-cdk/aws-logs/README.md @@ -36,12 +36,12 @@ Create a `SubscriptionFilter`, initialize it with an appropriate `Pattern` (see below) and supply the intended destination: ```ts -const lambda = new Lambda(this, 'Lambda', { ... }); +const fn = new lambda.Function(this, 'Lambda', { ... }); const logGroup = new LogGroup(this, 'LogGroup', { ... }); new SubscriptionFilter(this, 'Subscription', { logGroup, - destination: lambda, + destination: fn, filterPattern: FilterPattern.allTerms("ERROR", "MainThread") }); ``` diff --git a/packages/@aws-cdk/aws-sns/lib/topic-ref.ts b/packages/@aws-cdk/aws-sns/lib/topic-ref.ts index 726bc90017da7..d12753da83ea6 100644 --- a/packages/@aws-cdk/aws-sns/lib/topic-ref.ts +++ b/packages/@aws-cdk/aws-sns/lib/topic-ref.ts @@ -109,7 +109,7 @@ export abstract class TopicRef extends cdk.Construct implements events.IEventRul * @param name A name for the subscription * @param lambdaFunction The Lambda function to invoke */ - public subscribeLambda(lambdaFunction: lambda.LambdaRef) { + public subscribeLambda(lambdaFunction: lambda.FunctionRef) { const subscriptionName = lambdaFunction.name + 'Subscription'; if (this.tryFindChild(subscriptionName)) { diff --git a/packages/@aws-cdk/aws-sns/test/integ.sns-lambda.ts b/packages/@aws-cdk/aws-sns/test/integ.sns-lambda.ts index ca1b1ef9379d5..c5cc6584d70e2 100644 --- a/packages/@aws-cdk/aws-sns/test/integ.sns-lambda.ts +++ b/packages/@aws-cdk/aws-sns/test/integ.sns-lambda.ts @@ -8,7 +8,7 @@ class SnsToSqs extends cdk.Stack { const topic = new sns.Topic(this, 'MyTopic'); - const fction = new lambda.InlineJavaScriptLambda(this, 'Echo', { + const fction = new lambda.InlineJavaScriptFunction(this, 'Echo', { handler: { fn: (event, _context, callback) => { // tslint:disable:no-console diff --git a/packages/@aws-cdk/aws-sns/test/test.sns.ts b/packages/@aws-cdk/aws-sns/test/test.sns.ts index b7dc38c05e7f2..fdaf02b8ea88b 100644 --- a/packages/@aws-cdk/aws-sns/test/test.sns.ts +++ b/packages/@aws-cdk/aws-sns/test/test.sns.ts @@ -215,7 +215,7 @@ export = { displayName: 'displayName' }); - const fction = new lambda.InlineJavaScriptLambda(stack, 'MyFunc', { + const fction = new lambda.InlineJavaScriptFunction(stack, 'MyFunc', { handler: { fn: (_event, _context, callback) => callback() } @@ -351,7 +351,7 @@ export = { }); const queue = new sqs.Queue(stack, 'MyQueue'); - const func = new lambda.InlineJavaScriptLambda(stack, 'MyLambda', { + const func = new lambda.InlineJavaScriptFunction(stack, 'MyLambda', { handler: { fn: (_event, _context, callback: any) => callback() } diff --git a/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.ts b/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.ts index f399e38257ee5..77dd56beab008 100644 --- a/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.ts +++ b/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.ts @@ -12,7 +12,7 @@ class TestStack extends cdk.Stack { super(parent, name); const queue = new sqs.Queue(this, 'MyQueue'); - const fn = new lambda.InlineJavaScriptLambda(this, 'MyFunction', { + const fn = new lambda.InlineJavaScriptFunction(this, 'MyFunction', { handler: { fn: runtimeCode }, }); diff --git a/packages/aws-cdk-all/package.json b/packages/aws-cdk-all/package.json deleted file mode 100644 index 847e33b641a62..0000000000000 --- a/packages/aws-cdk-all/package.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "name": "aws-cdk-all", - "private": true, - "version": "0.8.0", - "description": "A single package that provides all of the CDK dependencies", - "main": "index.js", - "types": "index.d.ts", - "repository": { - "type": "git", - "url": "git://github.com/awslabs/aws-cdk" - }, - "author": { - "name": "Amazon Web Services", - "url": "https://aws.amazon.com" - }, - "scripts": { - "build": "echo Nothing to do", - "test": "echo Nothing to do" - }, - "license": "Apache-2.0", - "dependencies": { - "@aws-cdk/aws-apigateway": "^0.8.0", - "@aws-cdk/aws-applicationautoscaling": "^0.8.0", - "@aws-cdk/aws-appsync": "^0.8.0", - "@aws-cdk/aws-athena": "^0.8.0", - "@aws-cdk/aws-autoscaling": "^0.8.0", - "@aws-cdk/aws-autoscalingplans": "^0.8.0", - "@aws-cdk/aws-batch": "^0.8.0", - "@aws-cdk/aws-budgets": "^0.8.0", - "@aws-cdk/aws-certificatemanager": "^0.8.0", - "@aws-cdk/aws-cloud9": "^0.8.0", - "@aws-cdk/aws-cloudformation": "^0.8.0", - "@aws-cdk/aws-cloudfront": "^0.8.0", - "@aws-cdk/aws-cloudtrail": "^0.8.0", - "@aws-cdk/aws-cloudwatch": "^0.8.0", - "@aws-cdk/aws-codebuild": "^0.8.0", - "@aws-cdk/aws-codecommit": "^0.8.0", - "@aws-cdk/aws-codedeploy": "^0.8.0", - "@aws-cdk/aws-codepipeline": "^0.8.0", - "@aws-cdk/aws-cognito": "^0.8.0", - "@aws-cdk/aws-config": "^0.8.0", - "@aws-cdk/aws-datapipeline": "^0.8.0", - "@aws-cdk/aws-dax": "^0.8.0", - "@aws-cdk/aws-directoryservice": "^0.8.0", - "@aws-cdk/aws-dms": "^0.8.0", - "@aws-cdk/aws-dynamodb": "^0.8.0", - "@aws-cdk/aws-ec2": "^0.8.0", - "@aws-cdk/aws-ecr": "^0.8.0", - "@aws-cdk/aws-ecs": "^0.8.0", - "@aws-cdk/aws-efs": "^0.8.0", - "@aws-cdk/aws-eks": "^0.8.0", - "@aws-cdk/aws-elasticache": "^0.8.0", - "@aws-cdk/aws-elasticbeanstalk": "^0.8.0", - "@aws-cdk/aws-elasticloadbalancing": "^0.8.0", - "@aws-cdk/aws-elasticloadbalancingv2": "^0.8.0", - "@aws-cdk/aws-elasticsearch": "^0.8.0", - "@aws-cdk/aws-emr": "^0.8.0", - "@aws-cdk/aws-events": "^0.8.0", - "@aws-cdk/aws-gamelift": "^0.8.0", - "@aws-cdk/aws-glue": "^0.8.0", - "@aws-cdk/aws-guardduty": "^0.8.0", - "@aws-cdk/aws-iam": "^0.8.0", - "@aws-cdk/aws-inspector": "^0.8.0", - "@aws-cdk/aws-iot": "^0.8.0", - "@aws-cdk/aws-kinesis": "^0.8.0", - "@aws-cdk/aws-kinesisanalytics": "^0.8.0", - "@aws-cdk/aws-kinesisfirehose": "^0.8.0", - "@aws-cdk/aws-kms": "^0.8.0", - "@aws-cdk/aws-lambda": "^0.8.0", - "@aws-cdk/aws-logs": "^0.8.0", - "@aws-cdk/aws-neptune": "^0.8.0", - "@aws-cdk/aws-opsworks": "^0.8.0", - "@aws-cdk/aws-rds": "^0.8.0", - "@aws-cdk/aws-redshift": "^0.8.0", - "@aws-cdk/aws-route53": "^0.8.0", - "@aws-cdk/aws-s3": "^0.8.0", - "@aws-cdk/aws-sdb": "^0.8.0", - "@aws-cdk/aws-serverless": "^0.8.0", - "@aws-cdk/aws-servicecatalog": "^0.8.0", - "@aws-cdk/aws-servicediscovery": "^0.8.0", - "@aws-cdk/aws-ses": "^0.8.0", - "@aws-cdk/aws-sns": "^0.8.0", - "@aws-cdk/aws-sqs": "^0.8.0", - "@aws-cdk/aws-ssm": "^0.8.0", - "@aws-cdk/aws-stepfunctions": "^0.8.0", - "@aws-cdk/aws-waf": "^0.8.0", - "@aws-cdk/aws-wafregional": "^0.8.0", - "@aws-cdk/aws-workspaces": "^0.8.0", - "@aws-cdk/cdk": "^0.8.0", - "@aws-cdk/cx-api": "^0.8.0", - "@aws-cdk/runtime-values": "^0.8.0" - }, - "keywords": [ - "aws", - "cdk" - ], - "pkglint": { - "ignore": true - } -}