I'm pretty new to AWS and SST. However, I've been playing around with the getting started project for SST for the past couple of days and have learned a ton. I'm using SST v2.47.3 because the project I'm working on is using that. For some reason, the hot reload feature of Live Lambda Development keeps using a version of code from yesterday. The version from yesterday was a simple echo that took a POST and returned what was sent. Ultimately, I want to do something more complex with the POST but the echo was for testing purposes. Since then, I've modified the lambda to just do this to test if hot reload works:
return {
statusCode: 200,
body: "Hot reload is working",
};
However, when I hit my endpoint, it returns the message I used when a user does not provide a message parameter with a POST from my old lambda function. Since then, I've used:
I continue to get the response from my old lambda. Any ideas of other things I can do?
It sounds like you're encountering a caching or deployment issue with SST (Serverless Stack) and AWS Lambda. This can happen due to various reasons, such as cached Lambda versions, CloudFormation stack issues, or even local development environment quirks. Here are some steps you can take to troubleshoot and resolve the issue:
Clear SST and AWS Caches
Delete .sst folder: You've already done this, but ensure it's completely removed.
Clear AWS Lambda Versions: If you're using Lambda versions, the old code might still be cached. Go to the AWS Lambda console, find your function, and check if there are multiple versions. If so, delete the old versions or ensure the correct version is being used.
Clear CloudFormation Stack: Sometimes, CloudFormation stacks can get stuck or not update properly. Use the AWS CloudFormation console to delete the stack manually and redeploy it.
Force Redeploy the Stack
Use the pnpm sst deploy command to force a full redeployment of your stack. This ensures that all resources are updated with the latest code.
If you're using pnpm sst dev, try stopping it and running pnpm sst deploy instead to ensure a clean deployment.
Check Lambda Function Configuration
Go to the AWS Lambda console and verify that the function code matches your latest changes.
Ensure that the correct handler file and function are being used.
Check the environment variables in the Lambda console to ensure they match your .env.dev file.
Verify API Gateway Configuration
If you're using API Gateway, ensure that the endpoint is pointing to the correct Lambda function.
Check the API Gateway console to ensure the integration request and response mappings are correct.
If you've made changes to the API Gateway, redeploy it manually from the console.
Check Local Development Environment
Ensure that your local environment is using the correct AWS profile. Run aws configure list to verify the active profile.
Double-check your .env.dev file to ensure it's being loaded correctly. You can add a console.log in your Lambda function to print the environment variables and verify they match your expectations.
If you're using pnpm sst dev, ensure that the Live Lambda Development feature is working correctly. Sometimes, stopping and restarting the development environment can help.
Rebuild and Restart
Run pnpm sst build to ensure your code is compiled correctly.
Stop any running pnpm sst dev processes and restart them.
Check for Lambda Aliases
If you're using Lambda aliases (e.g., dev, prod), ensure that the correct alias is being used. You can check this in the AWS Lambda console under the "Aliases" tab.
Debugging Steps
Add logging to your Lambda function to verify which code is being executed. For example: javascript Copy
console.log("Current Lambda code is running"); return { statusCode: 200, body: "Hot reload is working", };
Check the CloudWatch logs for your Lambda function to see if the logs match your expectations.
Recreate the Stack
If none of the above steps work, try completely removing and recreating the stack:
Run pnpm sst remove to delete the stack.
Manually delete any remaining resources in the AWS console (e.g., Lambda functions, API Gateway endpoints, etc.).
Run pnpm sst deploy to recreate the stack from scratch.
Update SST Version
If you're using an older version of SST (v2.47.3), consider updating to the latest version if possible. There might be bug fixes or improvements that address your issue.
Summary of Commands to Try bash Copy
rm -rf .sst node_modules pnpm install --force pnpm sst build
pnpm sst deploy
pnpm sst dev