-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[@aws-cdk/aws-lambda-nodejs] Unable to run lambda locally with sam local
after updating to [email protected]
#10367
Comments
Think this maybe linked to an issue I have at #9189 too. Local dev through "cdk synth --no-staging > template.yaml" then "echo '{}' | sam local invoke LambdaName --env-vars environment.json" isn't possible at the moment. |
Good point @dave-graham. I think I am using |
I stand corrected, it looks like |
@jogold thoughts? |
@priceld Do you have a workaround at the moment? |
@ryan-mars, no workaround at the moment. We are just pinned to v1.60.0 for now. |
@priceld can you summarize exactly what you expect for |
Is the issue that Making |
@jogold I guess it depends on the the purpose of the But @ryan-mars is getting at my point - what I would really like to do (and what I've lost the ability to do after v1.61.0) is be able to run |
The change introduced in aws#9576 did not handle the "staging disabled" case. As a consequence, when bundling the staged path was always relative. Revert to the behavior that was present before this change: when staging is disabled the staged path is absolute (whether bundling or not). Closes aws#10367
The change introduced in aws#9576 did not handle the "staging disabled" case. As a consequence, when bundling the staged path was always relative. Revert to the behavior that was present before this change: when staging is disabled the staged path is absolute (whether bundling or not). Closes aws#10367
…0507) The change introduced in #9576 did not handle the "staging disabled" case. As a consequence, when bundling the staged path was always relative. Revert to the behavior that was present before this change: when staging is disabled the staged path is absolute (whether bundling or not). Closes #10367 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@priceld If for any reason in the future you need to patch relative paths to assets in a yaml file generated by CDK I'm using this. I know it's a little late and the issue is already closed. const yaml = require('js-yaml')
const fs = require('fs')
const path = require('path')
const { CLOUDFORMATION_SCHEMA } = require('cloudformation-js-yaml-schema')
const yamlPath = path.resolve('template.yaml')
if (!fs.existsSync(yamlPath)) throw `Your YAML isn't there: ${yamlPath}`
const template = yaml.safeLoad(fs.readFileSync(yamlPath, 'utf8'), {
schema: CLOUDFORMATION_SCHEMA
})
const countPatched = Object.keys(template.Resources)
.filter((resource) => template.Resources[resource].Type === 'AWS::Lambda::Function')
.reduce((count, resource) => {
const oldAssetPath = template.Resources[resource].Metadata['aws:asset:path']
if (fs.existsSync(path.resolve(oldAssetPath))) {
console.log(`Skipping ${resource} already a valid path\n${oldAssetPath}`)
return count
}
const newAssetPath = path.resolve('cdk.out', oldAssetPath)
if (!fs.existsSync(newAssetPath)) throw `There's no there, there: ${newAssetPath}`
console.log(`Fixing path for ${resource}`)
console.log(`${oldAssetPath} --> ${newAssetPath}`)
template.Resources[resource].Metadata['aws:asset:path'] = newAssetPath
return (count += 1)
}, 0)
console.log(`Fixed ${countPatched} resources.`)
if (countPatched > 0) {
console.log(`Writing ${yamlPath}`)
fs.writeFileSync(yamlPath, yaml.dump(template, { schema: CLOUDFORMATION_SCHEMA }))
} else {
console.log('Nothing to do, not touching the file.')
} |
I'm using @aws-cdk/aws-lambda-nodejs to bundle JS lambda code. However, after updating aws-cdk to v1.61.0 (or higher) I can no longer run
sam local
with the template thatcdk synth --no-staging
generates. I believe this is because f5c9124 changedasset-staging.ts
and now the template uses a differentaws:asset:path
for nodejs lambdas.This is the
Metadata
of a working template:Versus that of a failing template:
As you can see the path is different. When SAM tries to mount the lambda code to the docker image, this new relative path causes it to use a folder that does not contain the lambda code. The result is that when the lambda invoked, the code cannot be found and I get this error:
Reproduction Steps
I created this repo to demonstrate this bug and provide steps to reproduce.
What did you expect to happen?
I expected the lambda to run successfully.
What actually happened?
I see an error when trying to invoke the lambda:
Environment
Edit: Remove--no-staging
flag fromcdk synth
Edit: Undo previous edit.
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: