Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-cdk-lib): Python 3.6 dperecation for Lambda breaks #155

Open
AlphaDork opened this issue Jul 30, 2022 · 1 comment
Open

fix(aws-cdk-lib): Python 3.6 dperecation for Lambda breaks #155

AlphaDork opened this issue Jul 30, 2022 · 1 comment

Comments

@AlphaDork
Copy link

Hi David, working through your pluralsight course (which is fantastic! BTW). Implementing Serverless Web Application Hosting and Delivery on AWS - I am in the section where you first deploy the React App using the CDK... and I'm getting an error.

After some sleuthing - there is what I think is a breaking change in the aws-cdk-lib library where they deprecated python3.6 in favor of python3.9 as of like 7/22/22.

See the related AWS CL deprecating Python 3.6 here: aws/aws-cdk#20647

Here is the Error message I get on deployment:

Resource handler returned message: "The runtime parameter of python3.6 is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (python3.9) while creating or updating functions. (Service: L
ambda, Status Code: 400, Request ID: 5411f42d-3a3e-4c21-af63-ce423f3dc0f4)" (RequestToken: c0c306e7-3499-a21a-26d5-d3fcb99154ff, HandlerErrorCode: InvalidRequest)```
@gauravinthevalley
Copy link

gauravinthevalley commented Aug 10, 2022

@AlphaDork

I ran into the exact same issue. After some googling around, I found out that I had to migrate to v2 of the AWS CDK. I did that and now the code below wouldn't work.

`
new cwt.WebAppDeployment(this, 'WebAppDeploy', {

        baseDirectory: props.baseDirectory,

        relativeWebAppPath: props.relativeWebAppPath,

        webDistribution: this.webDistribution,

        webDistributionPaths: ['/*'],

        buildCommand: 'yarn build',

        buildDirectory: 'build',

        bucket: props.hostingBucket,

        prune: true

    })

`

After googling around and borrowing a bit from @davidtucker 's code here https://github.com/davidtucker/cdk-webapp-tools/blob/main/src/WebAppDeployment.ts (line 143 onward), I changed the code block above to the one below:

`
new s3Deploy.BucketDeployment(this, 'WebAppDeploy', {

        prune: true,

        distribution: this.webDistribution,

        distributionPaths: ['/*'],

        sources: [s3Deploy.Source.asset(path.join(__dirname, '../../../webapp/build'))],

        destinationBucket: props.hostingBucket,

    });

`

And now it works!

I also had to run yarn build manually under the webapp directory along with deleting all of the stacks and bootstrapping again; at one point I think I also deleted cdk.out. After the CDK v1 to v2 migration which essentially was changing imports and updating package.json and cdk.json under the infrastructure directory , npx cdk deploy was seamless.

Here's that updated package.json:

`
{

"name": "@ps-serverless/infrastructure",

"version": "0.1.0",

"bin": {

"infrastructure": "bin/infrastructure.js"

},

"scripts": {

"build": "tsc",

"watch": "tsc -w",

"test": "jest",

"cdk": "cdk"

},

"devDependencies": {

"@aws-cdk/assert": "^2.35.0",

"@types/jest": "^26.0.10",

"@types/node": "10.17.27",

"@types/source-map-support": "^0.5.4",

"aws-cdk": "2.33.0",

"esbuild": "^0.14.53",

"jest": "^26.4.2",

"ts-jest": "^26.2.0",

"ts-node": "^9.0.0",

"typescript": "~3.9.7"

},
"dependencies": {

"@aws-cdk/core": "^1.167.0",

"aws-cdk-lib": "2.33.0",

"cdk-webapp-tools": "2.10.4",

"constructs": "^10.0.0",

"source-map-support": "^0.5.16"

}

}
`

And here's the updated cdk.json:
`
{

"app": "npx ts-node --prefer-ts-exts bin/infrastructure.ts"

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants