AWS Skill Builder CDK Primer: TypeScript compile error TS2345 in sample code #20043
Replies: 3 comments 5 replies
-
Migrating this to a discussion @owenblacker 🙂 |
Beta Was this translation helpful? Give feedback.
-
Edit: Apps extend Construct, so you can use construct here. should've known that We don't have any ownership over the skill builder courses as far as I'm aware. So, I will suggest looking at our official documentation and guides instead 🙂 Let me know if you have any more questions or concerns I can help you with! |
Beta Was this translation helpful? Give feedback.
-
I had the same problem, but this advice got me on the right track. The problem is that Amazon's CDK primer assumes we're using AWS CDK v1, but the files they provide contain a mix of both v1 and v2 dependencies (see here for more information). Perhaps this could be passed along to whomever has ownership of the primer. I fixed the problem in this way:
This allowed me to synthesize the app and move forward in the primer. My files ended up looking like this. 👇 package.json {
"name": "cdk_primer",
"version": "0.1.0",
"bin": {
"cdk_primer": "bin/cdk_primer.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk"
},
"devDependencies": {
"@types/jest": "^27.5.2",
"@types/node": "10.17.27",
"@types/prettier": "2.6.0",
"aws-cdk": "2.32.0",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"ts-node": "^10.8.1",
"typescript": "~3.9.7"
},
"dependencies": {
"aws-cdk-lib": "2.32.0",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
}
} cdk_primer.ts #!/usr/bin/env node
import 'source-map-support/register';
import { App } from 'aws-cdk-lib';
import { CdkPrimerStack } from '../lib/cdk_primer-stack';
const app = new App();
new CdkPrimerStack(app, 'CdkPrimerStack', {
/* If you don't specify 'env', this stack will be environment-agnostic.
* Account/Region-dependent features and context lookups will not work,
* but a single synthesized template can be deployed anywhere. */
/* Uncomment the next line to specialize this stack for the AWS Account
* and Region that are implied by the current CLI configuration. */
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
/* Uncomment the next line if you know exactly what Account and Region you
* want to deploy the stack to. */
// env: { account: '123456789012', region: 'us-east-1' },
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
}); cdk_primer-stack.ts import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as ecs_patterns from 'aws-cdk-lib/aws-ecs-patterns';
export class CdkPrimerStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, "MyVpc", {maxAzs: 2});
const cluster = new ecs.Cluster(this, "MyCluster", {vpc: vpc});
new ecs_patterns.ApplicationLoadBalancedFargateService(this, "MyFargateService", {
cluster: cluster,
taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample")},
publicLoadBalancer: true
});
}
} |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Following the instructions in the AWS CDK Demonstration code-along in AWS Skill Builder and the first time I'm asked to
cdk synth
I get a compilation error, unlike the demonstration video.Expected Behavior
I expected the
cdk synth
to execute correctly, outputting a non-error response that endslike on-screen.
Current Behavior
I get an error response, with the error occurring in one of the files I have not changed. (The instructions have only asked me to change the file
lib/cdk_primer-stack.ts
so far; I have not editedbin/cdk-primer.ts
.)Reproduction Steps
Following the instructions in the video, I have done the following:
sudo npm i -g aws-cdk
/Users/owen.blacker/Projects/other/cdk-primer/
)cdk init --language typescript
npm i @aws-cdk/aws-ec2 @aws-cdk/aws-ecs @aws-cdk/aws-ecs-patterns
lib/cdk_primer-stack.ts
to contain the TypeScript as belowcdk synth
The contents of
lib/cdk_primer-stack.ts
once edited are:Other than the video having an extra tab at the start of line 12 (
new ecs_patterns.ApplicationLoadBalancedFargateService(...)
) and an extra linebreak after thatnew
statement, this is identical to the code on-screen.Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.21.0 (build 3f74a81)
Framework Version
No response
Node.js Version
v16.14.2
OS
MacOS Monterey version 12.3.1 (21E258)
Language
Typescript
Language Version
TypeScript 3.9.10
Other information
No response
Beta Was this translation helpful? Give feedback.
All reactions