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.48k stars 1.16k forks source link

Bug: Error publishing serverless application (Missing required parameter in input: "ApplicationId") #6566

Closed jcsobrino closed 1 week ago

jcsobrino commented 7 months ago

Description:

SAM CLI publish command fails updating an already existing serverless application. Diving into the code, we have observed SAM CLI firstly tries to create the application. If it already exists, it extracts from the error message the Application ID. Then, it updates the application with that Application ID.

However, in our case, AWS returns this error message:

An error occurred (ConflictException) when calling the CreateApplication operation: Application with name <application-name> already exists

instead of something like this:

An error occurred (ConflictException) when calling the CreateApplication operation: Application with id arn:aws:serverlessrepo:<region>:<account-id>:applications/<application-name> already exists

So, the regular expression does not match with the error message, it cannot extract the Application ID and the updating operation fails.

Steps to reproduce:

We execute these commands in a GitHub action, but the result it is the same from the shell in a local computer. The error raises in the last command.

sam validate
sam build
sam package --s3-bucket serverless-applications --output-template-file packaged.yaml
sam publish --region us-east-1 --template packaged.yaml

Observed result:

Error: Parameter validation failed:
Missing required parameter in input: "ApplicationId"

Expected result:

The serverless application is updated successfully.

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

  1. OS: macOS-14.0-arm64-arm-64bit
  2. sam --version: 1.105.0
  3. AWS region: us-east-1
sam --info

{
  "version": "1.105.0",
  "system": {
    "python": "3.11.4",
    "os": "macOS-14.0-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "20.10.16",
    "aws_cdk": "Not available",
    "terraform": "1.4.0"
  },
  "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"
  ]
}
hnnasit commented 7 months ago

Hi @jcsobrino, thanks for reporting the issue. I could not reproduce the behavior on my machine. When I try to re-run sam publish to update the application, the create_application API throws the error ConflictException('An error occurred (ConflictException) when calling the CreateApplication operation: Application with id <Application-id> already exists.') . Here's the project I used: template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  sam-app-6566

  Sample SAM Template for sam-app-6566

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3
    MemorySize: 128

Metadata:
  AWS::ServerlessRepo::Application:
    Author: user
    Description: description
    HomePageUrl: https://github.com/test/test
    Labels:
    - test-app
    LicenseUrl: ./LICENSE.txt
    Name: sam-app-6566
    ReadmeUrl: ./README.md
    SemanticVersion: 0.0.1
    SourceCodeUrl: https://github.com/test/test

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.9
      Architectures:
        - x86_64
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get

directory

├── .gitignore
├── LICENSE.txt
├── README.md
├── __init__.py
├── events
│   └── event.json
├── hello_world
│   ├── __init__.py
│   ├── app.py
│   └── requirements.txt
├── packaged.yaml
├── samconfig.toml
├── template.yaml

Can you provide a sample app for us to reproduce the behavior and the steps to update which results in the error? This seems similar to the issue, but would like to reproduce the behavior before marking this as a bug.

mildaniel commented 1 week ago

Closing due to inactivity. If the issue persists, please open a new issue.

github-actions[bot] commented 1 week ago

⚠️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.