aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.49k stars 1.17k forks source link

sam pipeline github action errors\issues #5966

Open paulthorburn opened 11 months ago

paulthorburn commented 11 months ago

Description:

When using sam pipeline on a new project from the python template (have not checked other languages) there is 2 issues

  1. When you initialize a project with sam init the default samconfig.toml includes the following [default.deploy.parameters] resolve_s3 = true

[default.package.parameters] resolve_s3 = true

during the 'build and package' phase it will results in the following error in the github action Error: Cannot use both --resolve-s3 and --s3-bucket parameters. Please use only one. Error: Process completed with exit code 1.

Removing the 2 "resolve_s3 = true" lines resolves the issue

  1. On a new project "confirm_changeset = true" when you use sam pipelines this will result in the testing phase reporting: Aborted! Deploy this changeset? [y/N]: Error: Process completed with exit code 1.

  2. This isn't a bug but I cannot figure out how to add parameter_overrides to pipelines using toml files. I tried adding it to [staging.pipeline_bootstrap.parameters] in pipelineconfg.toml i tried adding [staging.deploy.parameters] and [staging.pipeline_bootstrap.parameters] in samconfig.toml but nothing seemed to work. I can see that I can edit the github action script to add parameters but I feel like there is a better way?

Ideally when you run sam pipeline init it should prompt you to override parameters at each stage similar to sam build.

Steps to reproduce:

sam init 1 - AWS Quick Start Templates 1 - Hello World Example yes to Python and Zip no to X-Ray sam pipeline init --bootstrap select github actions

Observed result:

The github actions fail with the errors mentioned in points 1 and 2

Expected result:

After initializing a new project sam pipelines should work without errors

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

{ "version": "1.97.0", "system": { "python": "3.11.5", "os": "macOS-13.5.2-x86_64-i386-64bit" }, "additional_dependencies": { "docker_engine": "24.0.6", "aws_cdk": "2.53.0 (build 7690f43)", "terraform": "1.5.7" }, "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" ] }

mildaniel commented 11 months ago

Thanks @paulthorburn for reporting. The defaults we selected for the starter templates are human-focused and we expect that some might need to be changed to get the application working in a CI/CD system. With that being said, I can see how it might be frustrating to need to debug these things. We can definitely do a better job of documenting this or informing during instantiation.

I will mark this as a feature request for the team to prioritize.

paulthorburn commented 11 months ago

Hey @mildaniel thanks for getting back to me. Not sure if you know but in regards to my 3rd question is there a way to add parameter_overrides to pipelines in the toml files? or do i have to add it to the github action script directly?

If the default values are designed for someone to use with sam build and sam deploy perhaps when someone runs sam pipeline it can update the values in the toml file so that the pipeline works?

mildaniel commented 11 months ago

There isn't a way to specify specifically for pipelines since SAM CLI doesn't know if it's being executing on a CI/CD system or not. The best approach here would be to have parameter overrides directly in the script executing the deploy command.

mildaniel commented 11 months ago

If anyone else is facing a similar issue with executing SAM CLI commands in CI/CD environments, remove all defaults from the samconfig.toml deploy configuration and subsequent deployments should work as expected.

josephearl commented 3 months ago

Ran into this today. It is frustrating that sam pipeline init --bootstrap does not create a working pipeline OOB.

Additionally the GitHub template uses deprecated GitHub Actions (upload-artifact@v3, configure-aws-credentials@v1-node16).

Tony-Lutz commented 2 weeks ago

Running into the same thing.

The behavior seems similar to:

  1. 4841

  2. https://repost.aws/questions/QUpCCMU_5NTFG8La_C-sLhTQ/deploying-sam-template-with-github-actions-error-cannot-use-both-resolve-s3-and-s3-bucket-parameters-in-non-guided-deployments