Skip to content

Commit 4247966

Browse files
authored
feat(lambda): introduce a new kind of Code, CfnParametersCode. (#2027)
This Code type is helpful when there is no local file/directory to use Assets with, and the Lambda is supposed to be deployed in a CodePipeline.
1 parent 0f6ce56 commit 4247966

File tree

9 files changed

+1356
-14
lines changed

9 files changed

+1356
-14
lines changed

packages/@aws-cdk/aws-codepipeline-actions/README.md

+43-1
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,22 @@ This package defines the following actions:
324324
changes from the people (or system) applying the changes.
325325
* **CloudFormationExecuteChangeSetAction** - Execute a change set prepared previously.
326326
327+
##### Lambda deployed through CodePipeline
328+
329+
If you want to deploy your Lambda through CodePipeline,
330+
and you don't use assets (for example, because your CDK code and Lambda code are separate),
331+
you can use a special Lambda `Code` class, `CfnParametersCode`.
332+
Note that your Lambda must be in a different Stack than your Pipeline.
333+
The Lambda itself will be deployed, alongside the entire Stack it belongs to,
334+
using a CloudFormation CodePipeline Action. Example:
335+
336+
[Example of deploying a Lambda through CodePipeline](test/integ.lambda-deployed-through-codepipeline.lit.ts)
337+
327338
#### AWS CodeDeploy
328339
329-
To use CodeDeploy in a Pipeline:
340+
##### Server deployments
341+
342+
To use CodeDeploy for EC2/on-premise deployments in a Pipeline:
330343
331344
```ts
332345
import codedeploy = require('@aws-cdk/aws-codedeploy');
@@ -348,6 +361,35 @@ pipeline.addStage({
348361
});
349362
```
350363
364+
##### Lambda deployments
365+
366+
To use CodeDeploy for blue-green Lambda deployments in a Pipeline:
367+
368+
```typescript
369+
const lambdaCode = lambda.Code.cfnParameters();
370+
const func = new lambda.Function(lambdaStack, 'Lambda', {
371+
code: lambdaCode,
372+
handler: 'index.handler',
373+
runtime: lambda.Runtime.NodeJS810,
374+
});
375+
// used to make sure each CDK synthesis produces a different Version
376+
const version = func.newVersion();
377+
const alias = new lambda.Alias(lambdaStack, 'LambdaAlias', {
378+
aliasName: 'Prod',
379+
version,
380+
});
381+
382+
new codedeploy.LambdaDeploymentGroup(lambdaStack, 'DeploymentGroup', {
383+
alias,
384+
deploymentConfig: codedeploy.LambdaDeploymentConfig.Linear10PercentEvery1Minute,
385+
});
386+
```
387+
388+
Then, you need to create your Pipeline Stack,
389+
where you will define your Pipeline,
390+
and deploy the `lambdaStack` using a CloudFormation CodePipeline Action
391+
(see above for a complete example).
392+
351393
#### AWS S3
352394
353395
To use an S3 Bucket as a deployment target in CodePipeline:

0 commit comments

Comments
 (0)