Skip to content

fix: NodeJS sample #1840

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

maxday
Copy link
Member

@maxday maxday commented May 31, 2025

fixes: #1841

This PR updates the Node.js sample to bring it in line with current practices.

Now that Lambda layers are published, the sample app has been updated to use them.

The telemetry example now uses STS instead of S3 to still demonstrate telemetry capabilities but to avoid potential IAM permission issues caused by misconfigurations as STS GetCallerIdentidy does not need any special IAM permissions.

The AWS SDK has been upgraded to v3, enabling modular imports.

Infrastructure code has been migrated from Terraform to CDK to reduce external dependencies and improve alignment with the Node.js ecosystem, particularly due to its compatibility with npm-based tooling. Open to reverting this change if there's a strong preference for Terraform.

@maxday maxday requested a review from a team as a code owner May 31, 2025 13:20
@wpessers
Copy link
Contributor

wpessers commented Jun 2, 2025

Overall I like how you simplified the example somewhat by swapping the s3 integration for sts. And I appreciate the effort put into getting this sample way more polished!

Your point about cdk makes sense to me, the only reason I'm not sure about that one is that all the other language-specific samples use terraform. As far as I can tell that's just been a decision that was made at some point in the past. But to me it would make sense to keep that uniform accross all language-specific samples here. Maybe this should be a different issue altogether to explore whether we want to switch the samples from terraform over to cdk?

@maxday
Copy link
Member Author

maxday commented Jun 10, 2025

as discussed during the SIG meeting, I've put back the terraform (with some enhancement to use the hosted pre-built layers)
tested locally with terraform init + apply
here is the (truncated) output to show that this is working.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

module.hello-lambda-function.aws_lambda_function.this[0]: Modifying... [id=hello-nodejs-awssdk]
module.hello-lambda-function.aws_lambda_function.this[0]: Still modifying... [id=hello-nodejs-awssdk, 00m10s elapsed]
module.hello-lambda-function.aws_lambda_function.this[0]: Modifications complete after 15s [id=hello-nodejs-awssdk]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Outputs:

api-gateway-url = "https://[redacted].execute-api.us-east-2.amazonaws.com/default"
function_role_name = "hello-nodejs-awssdk"
maxday@Maximes-MBP wrapper % curl https://[redacted].execute-api.us-east-2.amazonaws.com/default
{"message":"Caller identity retrieved successfully","identity":{"Account":"[redacted]","Arn":"arn:aws:sts::[redacted]:assumed-role/hello-nodejs-awssdk/hello-nodejs-awssdk","UserId":"[redacted]:hello-nodejs-awssdk"}}

Let me know if this is looking good :)
Next step is to have a CI to build and test those samples I think.
Thanks!

@wpessers
Copy link
Contributor

LGTM!

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

Successfully merging this pull request may close these issues.

Node.js: sample code is not up to date
2 participants