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

Bug: ValueError when executing sam init #6998

Closed
ElrohirGT opened this issue Apr 30, 2024 · 3 comments
Closed

Bug: ValueError when executing sam init #6998

ElrohirGT opened this issue Apr 30, 2024 · 3 comments
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.

Comments

@ElrohirGT
Copy link

ElrohirGT commented Apr 30, 2024

Description:

Hi! First time SAM user here! I tried to install SAM using the package from Nix. I tried running the command sam init.

I tried searching for a similar issue but couldn't find one for the sam init command, only for sam deploy.

Steps to reproduce:

Install sam from nix. Here's a basic flake to do so:

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-23.11";
    systems.url = "github:nix-systems/default";
    devenv = {
      url = "github:cachix/devenv";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  nixConfig = {
    extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
    extra-substituters = "https://devenv.cachix.org";
  };

  outputs = {
    self,
    nixpkgs,
    systems,
    devenv,
    ...
  } @ inputs: let
    forEachSystem = nixpkgs.lib.genAttrs (import systems);
  in {
    packages = forEachSystem (
      system: let
        # dbPort = "5433";
        pkgs = import nixpkgs {inherit system;};
      in {
        # For setting up devenv
        devenv-up = self.devShells.${system}.default.config.procfileScript;
      }
    );

    devShells = forEachSystem (system: let
      pkgs = import nixpkgs {inherit system;};
    in {
      default = devenv.lib.mkShell {
        inherit pkgs inputs;
        modules = [
          {
            packages = with pkgs; [
              # General
              awscli2
              aws-sam-cli
            ];
          }
        ];
      };
    });
  };
}

Observed result:

2024-04-29 19:31:48,781 | Config file location: /home/elrohirgt/Documents/Development/samconfig.toml
2024-04-29 19:31:48,781 | Config file '/home/elrohirgt/Documents/Development/samconfig.toml' does not exist
2024-04-29 19:31:48,781 | Using config file: samconfig.toml, config environment: default
2024-04-29 19:31:48,781 | Expand command line arguments to:
2024-04-29 19:31:48,781 | --package_type=Zip --output_dir=. 

You can preselect a particular runtime or package type when using the `sam init` experience.
Call `sam init --help` to learn more.

Which template source would you like to use?
	1 - AWS Quick Start Templates
	2 - Custom Template Location
Choice: 
Choose an AWS Quick Start application template
	1 - Hello World Example
	2 - Data processing
	3 - Hello World Example with Powertools for AWS Lambda
	4 - Multi-step workflow
	5 - Scheduled task
	6 - Standalone function
	7 - Serverless API
	8 - Infrastructure event management
	9 - Lambda Response Streaming
	10 - Serverless Connector Hello World Example
	11 - Multi-step workflow with Connectors
	12 - Full Stack
	13 - Lambda EFS example
	14 - DynamoDB Example
	15 - Machine Learning
Template: 
Which runtime would you like to use?
	1 - dotnet6
	2 - nodejs18.x
	3 - nodejs16.x
	4 - nodejs14.x
	5 - nodejs12.x
Runtime: 
Based on your selections, the only Package type available is Zip.
We will proceed to selecting the Package type as Zip.

Based on your selections, the only dependency manager available is npm.
We will proceed copying the template using npm.

Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]: 
Would you like to enable monitoring using CloudWatch Application Insights?
For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]: 
Project name [sam-app]: 
    -----------------------
    Generating application:
    -----------------------
    Name: sam-app
    Runtime: nodejs18.x
    Architectures: x86_64
    Dependency Manager: npm
    Application Template: quick-start-web
    Output Directory: .
    Configuration file: sam-app/samconfig.toml
    
    Next steps can be found in the README file at sam-app/README.md
        

Commands you can use next
=========================
[*] Create pipeline: cd sam-app && sam pipeline init --bootstrap
[*] Validate SAM template: cd sam-app && sam validate
[*] Test Function in the Cloud: cd sam-app && sam sync --stack-name {stack-name} --watch

2024-04-29 19:32:14,055 | Parameters dict created with input given
2024-04-29 19:32:14,055 | {'template': '/home/elrohirgt/.aws-sam/aws-sam-cli-app-templates/nodejs18.x/web', 'output_dir': '.', 'no_input': True, 'extra_context': {'project_name': 'sam-app', 'runtime': 'nodejs18.x', 'architectures': {'value': ['x86_64']}}}
2024-04-29 19:32:14,055 | Baking a new template with cookiecutter with all parameters
2024-04-29 19:32:14,055 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics

Error: ['x86_64'] provided for multi-choice variable value, but valid choices are []
Traceback:
  File "/nix/store/zkdgc5dl5s643jngsg4wd3gdvbk5wydq-python3.11-click-8.1.7/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/nix/store/zkdgc5dl5s643jngsg4wd3gdvbk5wydq-python3.11-click-8.1.7/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zkdgc5dl5s643jngsg4wd3gdvbk5wydq-python3.11-click-8.1.7/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zkdgc5dl5s643jngsg4wd3gdvbk5wydq-python3.11-click-8.1.7/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/commands/init/command.py", line 102, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zkdgc5dl5s643jngsg4wd3gdvbk5wydq-python3.11-click-8.1.7/lib/python3.11/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zkdgc5dl5s643jngsg4wd3gdvbk5wydq-python3.11-click-8.1.7/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/lib/telemetry/metric.py", line 184, in wrapped
    raise exception  # pylint: disable=raising-bad-type
    ^^^^^^^^^^^^^^^
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/lib/telemetry/metric.py", line 149, in wrapped
    return_value = func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
    actual_result = func(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/cli/main.py", line 95, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/commands/init/command.py", line 256, in cli
    do_cli(
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/commands/init/command.py", line 352, in do_cli
    do_interactive(
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/commands/init/interactive_init_flow.py", line 68, in do_interactive
    generate_application(
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/commands/init/interactive_init_flow.py", line 137, in generate_application
    _generate_from_use_case(
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/commands/init/interactive_init_flow.py", line 284, in _generate_from_use_case
    do_generate(
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/commands/init/init_generator.py", line 23, in do_generate
    generate_project(
  File "/nix/store/zwkszbxjd529ywv1dhi6cg17f1qk6fnv-aws-sam-cli-1.90.0/lib/python3.11/site-packages/samcli/lib/init/__init__.py", line 107, in generate_project
    cookiecutter(**params)
  File "/nix/store/sy03vz2rlqs28x9a0m45ji3m1h9a7wk3-python3.11-cookiecutter-2.3.0/lib/python3.11/site-packages/cookiecutter/main.py", line 116, in cookiecutter
    context = generate_context(
              ^^^^^^^^^^^^^^^^^
  File "/nix/store/sy03vz2rlqs28x9a0m45ji3m1h9a7wk3-python3.11-cookiecutter-2.3.0/lib/python3.11/site-packages/cookiecutter/generate.py", line 131, in generate_context
    apply_overwrites_to_context(obj, extra_context)
  File "/nix/store/sy03vz2rlqs28x9a0m45ji3m1h9a7wk3-python3.11-cookiecutter-2.3.0/lib/python3.11/site-packages/cookiecutter/generate.py", line 83, in apply_overwrites_to_context
    apply_overwrites_to_context(context_value, overwrite)
  File "/nix/store/sy03vz2rlqs28x9a0m45ji3m1h9a7wk3-python3.11-cookiecutter-2.3.0/lib/python3.11/site-packages/cookiecutter/generate.py", line 64, in apply_overwrites_to_context
    raise ValueError(

An unexpected error was encountered while executing "sam init".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20init%20-%20ValueError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20init%20-%20ValueError

Expected result:

I expected the project to be initialized correctly without errors

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Linux
  2. sam --version: 1.90
  3. AWS region:
{
  "version": "1.90.0",
  "system": {
    "python": "3.11.8",
    "os": "Linux-6.1.87-x86_64-with-glibc2.38"
  },
  "additional_dependencies": {
    "docker_engine": "24.0.5",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Add --debug flag to command you are running

@ElrohirGT ElrohirGT added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Apr 30, 2024
@mildaniel
Copy link
Contributor

Hey @ElrohirGT, thanks for creating the issue. I wasn't able to reproduce the issue, however, it seems like the package manager you are using is giving you an outdated version of SAM CLI. We don't own or distribute through Nix so we have no control over it. I recommend using our native installers as outlined in our documentation. Let us know if this helps!

@mildaniel mildaniel added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Apr 30, 2024
@ElrohirGT
Copy link
Author

You're right! Thanks a bunch it works now that I use the latest version!

The problem for someone else using nix too was that in my flake I was referring to:

inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-23.11";
...

When I should be referring to:

inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";

To get the latest version of everything. Thanks for the help @mildaniel and sorry for the inconvenience!

Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.
Projects
None yet
Development

No branches or pull requests

2 participants