Skip to content

Commit 149b88d

Browse files
authored
Merge branch 'main' into mrgrain/chore/integ-runner-toolkit-lib
2 parents 65db1be + 6bd78f7 commit 149b88d

File tree

4 files changed

+125
-6
lines changed

4 files changed

+125
-6
lines changed

.github/workflows/codecov-upload.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ jobs:
2424
uses: actions/download-artifact@v4
2525
with:
2626
name: coverage-artifacts
27-
path: ./coverage
27+
path: ./coverage/packages/aws-cdk-lib/core/coverage
2828
github-token: ${{ secrets.GITHUB_TOKEN }}
2929
repository: ${{ github.repository }}
3030
run-id: ${{ github.event.workflow_run.id }}
3131

3232
- name: Upload to Codecov
3333
uses: codecov/codecov-action@v5
3434
with:
35-
files: ./coverage/packages/aws-cdk-lib/coverage/cobertura-coverage.xml
35+
files: ./coverage/packages/aws-cdk-lib/core/coverage/cobertura-coverage.xml
3636
fail_ci_if_error: true
3737
flags: suite.unit
3838
use_oidc: true

.github/workflows/pr-build.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
name: PR Build
22

33
on:
4+
workflow_dispatch: {}
5+
merge_group: {}
6+
push:
7+
branches:
8+
- main
9+
- v2-release
410
pull_request:
511
branches:
612
- main
713
- v2-release
814

915
jobs:
1016
build:
11-
runs-on: aws-cdk_ubuntu-latest_16-core
17+
runs-on: aws-cdk_ubuntu-latest_32-core
1218

1319
env:
1420
PR_BUILD: true
@@ -18,7 +24,7 @@ jobs:
1824
uses: actions/checkout@v4
1925

2026
- name: Setup Node.js
21-
uses: actions/setup-node@v3
27+
uses: actions/setup-node@v4
2228
with:
2329
node-version: "18"
2430
cache: "yarn"
@@ -31,7 +37,7 @@ jobs:
3137
# run: /root/ecr-proxy/start.sh
3238

3339
- name: Cache build artifacts
34-
uses: actions/cache@v3
40+
uses: actions/cache@v4
3541
with:
3642
path: |
3743
~/.s3buildcache

packages/aws-cdk-lib/aws-lambda/lib/code.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,45 @@ import { UnscopedValidationError, ValidationError } from '../../core/lib/errors'
1515
export abstract class Code {
1616
/**
1717
* Lambda handler code as an S3 object.
18+
*
19+
* Note: If `objectVersion` is not defined, the lambda will not be updated automatically if the code in the bucket is updated.
20+
* This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion.
1821
* @param bucket The S3 bucket
1922
* @param key The object key
2023
* @param objectVersion Optional S3 object version
2124
*/
2225
public static fromBucket(bucket: s3.IBucket, key: string, objectVersion?: string): S3Code {
26+
if (objectVersion === undefined) {
27+
cdk.Annotations.of(bucket).addWarningV2(
28+
'@aws-cdk/aws-lambda:codeFromBucketObjectVersionNotSpecified',
29+
'objectVersion is not defined for S3Code.fromBucket(). The lambda will not be updated automatically if the code in the bucket is updated. ' +
30+
'This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion.',
31+
);
32+
}
33+
2334
return new S3Code(bucket, key, objectVersion);
2435
}
2536

2637
/**
2738
* Lambda handler code as an S3 object.
39+
*
40+
* Note: If `options.objectVersion` is not defined, the lambda will not be updated automatically if the code in the bucket is updated.
41+
* This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion.
2842
* @param bucket The S3 bucket
2943
* @param key The object key
3044
* @param options Optional parameters for setting the code, current optional parameters to set here are
3145
* 1. `objectVersion` to set S3 object version
3246
* 2. `sourceKMSKey` to set KMS Key for encryption of code
3347
*/
3448
public static fromBucketV2 (bucket: s3.IBucket, key: string, options?: BucketOptions): S3CodeV2 {
49+
if (options?.objectVersion === undefined) {
50+
cdk.Annotations.of(bucket).addWarningV2(
51+
'@aws-cdk/aws-lambda:codeFromBucketObjectVersionNotSpecified',
52+
'options.objectVersion is not defined for S3Code.fromBucketV2(). The lambda will not be updated automatically if the code in the bucket is updated. ' +
53+
'This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set options.objectVersion.',
54+
);
55+
}
56+
3557
return new S3CodeV2(bucket, key, options);
3658
}
3759

packages/aws-cdk-lib/aws-lambda/test/code.test.ts

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as child_process from 'child_process';
22
import * as path from 'path';
3-
import { Match, Template } from '../../assertions';
3+
import { Annotations, Match, Template } from '../../assertions';
44
import * as ecr from '../../aws-ecr';
5+
import * as s3 from '../../aws-s3';
56
import * as cdk from '../../core';
67
import * as cxapi from '../../cx-api';
78
import * as lambda from '../lib';
@@ -615,6 +616,96 @@ describe('code', () => {
615616
expect(cpMock).toHaveBeenCalledWith('/my/image/path/.', undefined);
616617
});
617618
});
619+
620+
describe('lambda.Code.fromBucket', () => {
621+
test('fromBucket warns when no objectVersion is set', () => {
622+
// given
623+
const app = new cdk.App();
624+
const stack = new cdk.Stack(app, 'Stack');
625+
const bucket = new s3.Bucket(stack, 'Bucket');
626+
627+
// when
628+
new lambda.Function(stack, 'Fn', {
629+
code: lambda.Code.fromBucket(bucket, 'Object'),
630+
handler: 'index.handler',
631+
runtime: lambda.Runtime.NODEJS_LATEST,
632+
});
633+
634+
// then
635+
Annotations.fromStack(stack).hasWarning(
636+
'/Stack/Bucket',
637+
'objectVersion is not defined for S3Code.fromBucket(). The lambda will not be updated automatically if the code in the bucket is updated. ' +
638+
'This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion. ' +
639+
'[ack: @aws-cdk/aws-lambda:codeFromBucketObjectVersionNotSpecified]',
640+
);
641+
});
642+
643+
test('fromBucket does not warn when an objectVersion is set', () => {
644+
// given
645+
const app = new cdk.App();
646+
const stack = new cdk.Stack(app, 'Stack');
647+
const bucket = new s3.Bucket(stack, 'Bucket');
648+
649+
// when
650+
new lambda.Function(stack, 'Fn', {
651+
code: lambda.Code.fromBucket(bucket, 'Object', 'v1'),
652+
handler: 'index.handler',
653+
runtime: lambda.Runtime.NODEJS_LATEST,
654+
});
655+
656+
// then
657+
Annotations.fromStack(stack).hasNoWarning(
658+
'/Stack/Bucket',
659+
'objectVersion is not defined for S3Code.fromBucket(). The lambda will not be updated automatically if the code in the bucket is updated. ' +
660+
'This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion. ' +
661+
'[ack: @aws-cdk/aws-lambda:codeFromBucketObjectVersionNotSpecified]',
662+
);
663+
});
664+
665+
test('fromBucketV2 warns when no objectVersion is set', () => {
666+
// given
667+
const app = new cdk.App();
668+
const stack = new cdk.Stack(app, 'Stack');
669+
const bucket = new s3.Bucket(stack, 'Bucket');
670+
671+
// when
672+
new lambda.Function(stack, 'Fn', {
673+
code: lambda.Code.fromBucketV2(bucket, 'Object'),
674+
handler: 'index.handler',
675+
runtime: lambda.Runtime.NODEJS_LATEST,
676+
});
677+
678+
// then
679+
Annotations.fromStack(stack).hasWarning(
680+
'/Stack/Bucket',
681+
'options.objectVersion is not defined for S3Code.fromBucketV2(). The lambda will not be updated automatically if the code in the bucket is updated. ' +
682+
'This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set options.objectVersion. ' +
683+
'[ack: @aws-cdk/aws-lambda:codeFromBucketObjectVersionNotSpecified]',
684+
);
685+
});
686+
687+
test('fromBucketV2 does not warn when an objectVersion is set', () => {
688+
// given
689+
const app = new cdk.App();
690+
const stack = new cdk.Stack(app, 'Stack');
691+
const bucket = new s3.Bucket(stack, 'Bucket');
692+
693+
// when
694+
new lambda.Function(stack, 'Fn', {
695+
code: lambda.Code.fromBucketV2(bucket, 'Object', { objectVersion: 'v1' }),
696+
handler: 'index.handler',
697+
runtime: lambda.Runtime.NODEJS_LATEST,
698+
});
699+
700+
// then
701+
Annotations.fromStack(stack).hasNoWarning(
702+
'/Stack/Bucket',
703+
'options.objectVersion is not defined for S3Code.fromBucketV2(). The lambda will not be updated automatically if the code in the bucket is updated. ' +
704+
'This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set options.objectVersion. ' +
705+
'[ack: @aws-cdk/aws-lambda:codeFromBucketObjectVersionNotSpecified]',
706+
);
707+
});
708+
});
618709
});
619710

620711
function defineFunction(code: lambda.Code, runtime: lambda.Runtime = lambda.Runtime.NODEJS_LATEST) {

0 commit comments

Comments
 (0)