Upgrading to 3.0¶
3.0.0 is a major release. This page lists every change that can affect an existing consumer, with what to do about it. Changes are marked intentional (a deliberate behavior or support change) or upgrade-induced (a consequence of the newer AWS CDK).
1. .NET 8 and .NET 9 are no longer supported (intentional)¶
The package targets net10.0 and net11.0 only. Projects on .NET 8 or 9 should stay on 2.x or move to .NET 10 or 11.
2. Amazon.CDK.Lib 2.278.0 or later (upgrade-induced)¶
The minimum AWS CDK version is now 2.278.0. Upgrade this library and Amazon.CDK.Lib together. With 2.6.0, WebFunctionConstruct was observed to fail at synthesis against Amazon.CDK.Lib 2.278.0 (MissingMethodException: Amazon.CDK.Annotations.AddWarningV2). If you stay on 2.x (for example on .NET 8 or 9) and use the Web Function constructs, keep Amazon.CDK.Lib below 2.278.0 (2.6.0 was built against 2.274.0 and was validated downstream with 2.275.0).
2.278.0 also adds AWS's own Web Function L2 types to Amazon.CDK.AWS.Lambda, and eight of their names match this library's:
IWebFunctionEndpoint(namespaceLayeredCraft.Cdk.Constructs);WebFunctionCode,WebFunctionRuntime,WebFunctionAuthType,WebFunctionEndpointType,WebFunctionEndpointOptions,IWebFunctionEndpointOptionsandWebFunctionEndpointAttributes(namespaceLayeredCraft.Cdk.Constructs.Models).
A file that imports both Amazon.CDK.AWS.Lambda and these namespaces gets CS0104 (ambiguous reference). Add file-local aliases for the types the file uses:
using Amazon.CDK.AWS.Lambda;
using LayeredCraft.Cdk.Constructs.Models;
using WebFunctionCode = LayeredCraft.Cdk.Constructs.Models.WebFunctionCode;
using WebFunctionRuntime = LayeredCraft.Cdk.Constructs.Models.WebFunctionRuntime;
This is a source-only change: synthesized templates are unchanged.
3. LambdaFunctionConstruct: invocation permissions default to the alias only (intentional)¶
Each LambdaPermission now has Targets (LambdaPermissionTargets flags: Function, Version, Alias). The default is Alias. In 2.x every permission was added to the function, the current version and the alias.
At the default, the function and version AWS::Lambda::Permission resources disappear from the template; the alias permission is unchanged (same logical ID):
// 2.x: three resources per permission
"…permissionfn0…": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Fn::GetAtt": ["…function…", "Arn"] }, … } },
"…permissionver0…": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Ref": "…CurrentVersion…" }, … } },
"…permissionalias0…": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Ref": "…alias…" }, … } }
// 3.0 default: the alias permission only
"…permissionalias0…": { "Type": "AWS::Lambda::Permission", "Properties": { "FunctionName": { "Ref": "…alias…" }, … } }
Callers that invoke the alias (for example an Alexa skill or API Gateway integration pointing at the alias ARN) need no change. To keep the 2.x output exactly, opt into all three targets:
new LambdaPermission
{
Principal = "apigateway.amazonaws.com",
Action = "lambda:InvokeFunction",
SourceArn = apiArn,
Targets = LambdaPermissionTargets.Function | LambdaPermissionTargets.Version | LambdaPermissionTargets.Alias,
}
A permission with no targets is rejected at synthesis.
4. LambdaFunctionConstruct: logging policy scoped to the construct's log group (intentional)¶
The execution role's logging policy now allows only logs:CreateLogStream and logs:PutLogEvents on the construct's own log group. logs:CreateLogGroup, logs:TagResource and the wildcard log-group ARN are removed; the construct creates the log group itself.
// 2.x
{ "Action": ["logs:CreateLogStream", "logs:CreateLogGroup", "logs:TagResource"], "Effect": "Allow",
"Resource": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/lambda/my-function-dev*:*" },
{ "Action": "logs:PutLogEvents", "Effect": "Allow",
"Resource": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/lambda/my-function-dev*:*:*" }
// 3.0
{ "Action": ["logs:CreateLogStream", "logs:PutLogEvents"], "Effect": "Allow",
"Resource": { "Fn::GetAtt": ["…loggroup…", "Arn"] } }
Deploying this updates the inline policy in place. If the function writes to other log groups, add statements through PolicyStatements.
5. New LambdaFunctionConstruct options (additive)¶
AliasName(defaultlive): the alias name. The alias keeps its logical ID, but CloudFormation replaces an alias whose name changes, so callers using the old alias ARN must be updated.AliasandVersion: the alias (IAlias) and current version (IVersion) are public properties.Code: anyAmazon.CDK.AWS.Lambda.Codesource as an alternative toAssetPath, for example an immutable artifact in an existing bucket. Exactly one ofAssetPathandCodemust be set.AssetPathis no longerrequired(it isstring?); existingAssetPathusage is unchanged.
var artifacts = Bucket.FromBucketName(this, "Artifacts", "my-artifacts-bucket");
new LambdaFunctionConstruct(this, "Worker", new LambdaFunctionConstructProps
{
FunctionName = "worker",
FunctionSuffix = "dev",
Code = Code.FromBucketV2(artifacts, "worker/1.2.3/worker.zip"),
RoleName = "worker-dev-role",
PolicyName = "worker-dev-policy",
});
The construct grants the function no access to the bucket and adds no bucket permissions.
ILambdaFunctionConstructProps gained Code and AliasName, and AssetPath became nullable. Custom implementations of the interface need those members.
Testing helpers: LambdaFunctionConstructPropsBuilder gained WithAliasName and WithCode, and WithApiGatewayPermission/WithAlexaPermission take an optional targets. LambdaFunctionConstructAssertions.ShouldHaveLambdaPermissions counts per selected target (default alias only), and ShouldHaveCloudWatchLogsPermissions asserts the scoped policy; its region and account parameters are kept for source compatibility and are ignored.
6. New PrivateStaticAssetsConstruct (additive)¶
A new construct for web assets in a private, versioned bucket behind CloudFront. It is additive: nothing changes for existing constructs, and StaticSiteConstruct is unchanged.
The bucket has S3 object versioning, but that does not make asset URLs immutable. Deployments go to the bucket root unless you set DestinationKeyPrefix. For immutable paths, pass a prefix that is unique per release (for example game/<commit-sha>/); with the default Prune = false, earlier prefixes remain available.
Use it instead of StaticSiteConstruct when the bucket must stay private:
StaticSiteConstruct | PrivateStaticAssetsConstruct | |
|---|---|---|
| Bucket access | Public-read website bucket, Block Public Access off | Block Public Access on; CloudFront origin access control only |
| Website endpoint | Yes | No |
| DNS and certificate | Required (Route53 lookup and ACM) | Optional; the CloudFront domain is used by default |
| SPA rewrites | Always on | Off by default |
| Deployment | Prunes, auto-deletes objects, bucket destroyed with the stack | Bucket root or a caller-supplied DestinationKeyPrefix; no prune; objects and bucket retained by default |
Switching an existing site from StaticSiteConstruct to the new construct is not a drop-in change. What happens depends on the construct ID:
- Same parent scope and construct ID: the distribution (
{id}-cdn) keeps its logical ID and is updated in place, so the CloudFront domain is kept. The bucket ({id}-bucket) is still replaced:StaticSiteConstructnames it after the site domain, and a bucket name cannot change in place. The DNS alias records use different construct IDs and are recreated. - New construct ID: every resource is new, including the distribution and its CloudFront domain.
In both cases, copy the content to the new bucket and review cdk diff before deploying. See Private Static Assets.
7. Consumer test projects¶
No change is required. The library's own tests moved from AutoFixture/NSubstitute to Compono; that does not affect the shipped Testing helpers' dependencies.