I’m working through the AWS Cloud Development Kit (CDK) tutorial at https://docs.aws.amazon.com/cdk/v2/guide/hello_world.html. Working in CloudShell, I got through step 7 with no trouble; step 6 produced the following template.
Resources:
HelloWorldFunctionServiceRole8E0BD458:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Version: "2012-10-17"
ManagedPolicyArns:
- Fn::Join:
- ""
- - "arn:"
- Ref: AWS::Partition
- :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Metadata:
aws:cdk:path: HelloCdkStack/HelloWorldFunction/ServiceRole/Resource
HelloWorldFunctionB2AB6E79:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: "
exports.handler = async function(event) {
return {
statusCode: 200,
body: JSON.stringify('Hello World!'),
};
};
"
Handler: index.handler
Role:
Fn::GetAtt:
- HelloWorldFunctionServiceRole8E0BD458
- Arn
Runtime: nodejs20.x
DependsOn:
- HelloWorldFunctionServiceRole8E0BD458
Metadata:
aws:cdk:path: HelloCdkStack/HelloWorldFunction/Resource
HelloWorldFunctionFunctionUrl4150BDAD:
Type: AWS::Lambda::Url
Properties:
AuthType: NONE
TargetFunctionArn:
Fn::GetAtt:
- HelloWorldFunctionB2AB6E79
- Arn
Metadata:
aws:cdk:path: HelloCdkStack/HelloWorldFunction/FunctionUrl/Resource
HelloWorldFunctioninvokefunctionurlA2CB1A84:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunctionUrl
FunctionName:
Fn::GetAtt:
- HelloWorldFunctionB2AB6E79
- Arn
FunctionUrlAuthType: NONE
Principal: "*"
Metadata:
aws:cdk:path: HelloCdkStack/HelloWorldFunction/invoke-function-url
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Analytics: v2:deflate64:H4sIAAAAAAAA/02MyQrCMBRFv6X75NkWEfcFt0rFtaRJhNdmkAy6CPl3mzjg6lzOgdtDt91B27Cnp1wsVOEE6RwYX8iqrkkxPQkG6RAND2gNGW7mt7/j4lTxH5yk0+j96jNBpiGNVskSCnMmo/Q2Ol7VMYZ7DDX+2cEagaEeGCskzH7z6PbQt9A3s0ekLpqAWsL45gvvKoubxQAAAA==
Metadata:
aws:cdk:path: HelloCdkStack/CDKMetadata/Default
Condition: CDKMetadataAvailable
Outputs:
myFunctionUrlOutput:
Value:
Fn::GetAtt:
- HelloWorldFunctionFunctionUrl4150BDAD
- FunctionUrl
Conditions:
CDKMetadataAvailable:
Fn::Or:
- Fn::Or:
- Fn::Equals:
- Ref: AWS::Region
- af-south-1
- Fn::Equals:
- Ref: AWS::Region
- ap-east-1
- Fn::Equals:
- Ref: AWS::Region
- ap-northeast-1
- Fn::Equals:
- Ref: AWS::Region
- ap-northeast-2
- Fn::Equals:
- Ref: AWS::Region
- ap-south-1
- Fn::Equals:
- Ref: AWS::Region
- ap-southeast-1
- Fn::Equals:
- Ref: AWS::Region
- ap-southeast-2
- Fn::Equals:
- Ref: AWS::Region
- ca-central-1
- Fn::Equals:
- Ref: AWS::Region
- cn-north-1
- Fn::Equals:
- Ref: AWS::Region
- cn-northwest-1
- Fn::Or:
- Fn::Equals:
- Ref: AWS::Region
- eu-central-1
- Fn::Equals:
- Ref: AWS::Region
- eu-north-1
- Fn::Equals:
- Ref: AWS::Region
- eu-south-1
- Fn::Equals:
- Ref: AWS::Region
- eu-west-1
- Fn::Equals:
- Ref: AWS::Region
- eu-west-2
- Fn::Equals:
- Ref: AWS::Region
- eu-west-3
- Fn::Equals:
- Ref: AWS::Region
- il-central-1
- Fn::Equals:
- Ref: AWS::Region
- me-central-1
- Fn::Equals:
- Ref: AWS::Region
- me-south-1
- Fn::Equals:
- Ref: AWS::Region
- sa-east-1
- Fn::Or:
- Fn::Equals:
- Ref: AWS::Region
- us-east-1
- Fn::Equals:
- Ref: AWS::Region
- us-east-2
- Fn::Equals:
- Ref: AWS::Region
- us-west-1
- Fn::Equals:
- Ref: AWS::Region
- us-west-2
Parameters:
BootstrapVersion:
Type: AWS::SSM::Parameter::Value<String>
Default: /cdk-bootstrap/hnb659fds/version
Description: Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]
Rules:
CheckBootstrapVersion:
Assertions:
- Assert:
Fn::Not:
- Fn::Contains:
- - "1"
- "2"
- "3"
- "4"
- "5"
- Ref: BootstrapVersion
AssertDescription: CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.
But when I run step 8, executing cdk deploy
, I get the following response:
❌ HelloCdkStack failed: Error [ValidationError]: Template format error: Unrecognized resource types: [AWS::Lambda::Url]
at Request.extractError (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:46723)
at Request.callListeners (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:91777)
at Request.emit (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:91225)
at Request.emit (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:199828)
at Request.transition (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:193380)
at AcceptorStateMachine.runTo (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:158252)
at /usr/local/lib/node_modules/aws-cdk/lib/index.js:401:158582
at Request.<anonymous> (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:193672)
at Request.<anonymous> (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:199903)
at Request.callListeners (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:91945) {
code: 'ValidationError',
time: 2024-08-12T18:34:33.761Z,
requestId: '0cc0f0d3-9940-495b-bf2a-f4578ef910f0',
statusCode: 400,
retryable: false,
retryDelay: 261.7239740021147
}
❌ Deployment failed: Error [ValidationError]: Template format error: Unrecognized resource types: [AWS::Lambda::Url]
at Request.extractError (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:46723)
at Request.callListeners (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:91777)
at Request.emit (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:91225)
at Request.emit (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:199828)
at Request.transition (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:193380)
at AcceptorStateMachine.runTo (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:158252)
at /usr/local/lib/node_modules/aws-cdk/lib/index.js:401:158582
at Request.<anonymous> (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:193672)
at Request.<anonymous> (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:199903)
at Request.callListeners (/usr/local/lib/node_modules/aws-cdk/lib/index.js:401:91945) {
code: 'ValidationError',
time: 2024-08-12T18:34:33.761Z,
requestId: '0cc0f0d3-9940-495b-bf2a-f4578ef910f0',
statusCode: 400,
retryable: false,
retryDelay: 261.7239740021147
So, CDK doesn’t recognize the AWS::Lambda::Url
resource type that CDK itself included in the template that it generated? I’m getting no clue from the error message as to what to do about this.