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

Skip Docker Lambda image builds when ImageUri is a valid ECR location #2934

Open
alexisfacques opened this issue Jun 6, 2021 · 20 comments
Open
Labels

Comments

@alexisfacques
Copy link
Contributor

alexisfacques commented Jun 6, 2021

Describe your idea/feature/enhancement

When configuring a lambda / serverless function of which the PackageType is Zip, SAM preemptively checks whether the resource CodeUri is a S3 location or not.

  # This function is already packaged and will to be ignored by SAM
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Zip
      CodeUri: s3://bucket/function.zip
      ...

If so, SAM will not attempt to build said lambda, and will show a warning to the user:

% sam build
The resource AWS::Serverless::Function 'Function' has specified S3 location for CodeUri. It will not be built and SAM CLI does not support invoking it locally.

I would expect SAM to do the same when attempting to build a PackageType: Image lambda function; checking whether or not the resource property ImageUri is a valid ECR URL before attempting to build said images locally, yet this feature is not supported by SAM today:

  # SAM should not attempt to build this Lambda
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/function:latest

Instead, attempting to do so will most likely output the following exception (as the DockerContext resource metadata, required for building Docker Images using SAM, will most likely be unset, error traced here):

% sam build
Building image for Function function
Traceback (most recent call last):
  File "/usr/local/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/usr/local/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
    return_value = func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
    actual_result = func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/samcli/commands/build/command.py", line 210, in cli
    do_cli(
  File "/usr/local/lib/python3.8/site-packages/samcli/commands/build/command.py", line 315, in do_cli
    artifacts = builder.build()
  File "/usr/local/lib/python3.8/site-packages/samcli/lib/build/app_builder.py", line 169, in build
    return build_strategy.build()
  File "/usr/local/lib/python3.8/site-packages/samcli/lib/build/build_strategy.py", line 41, in build
    result.update(self._build_functions(self._build_graph))
  File "/usr/local/lib/python3.8/site-packages/samcli/lib/build/build_strategy.py", line 52, in _build_functions
    function_build_results.update(self.build_single_function_definition(build_definition))
  File "/usr/local/lib/python3.8/site-packages/samcli/lib/build/build_strategy.py", line 118, in build_single_function_definition
    result = self._build_function(
  File "/usr/local/lib/python3.8/site-packages/samcli/lib/build/app_builder.py", line 500, in _build_function
    return self._build_lambda_image(function_name=function_name, metadata=metadata)  # type: ignore
  File "/usr/local/lib/python3.8/site-packages/samcli/lib/build/app_builder.py", line 322, in _build_lambda_image
    docker_context_dir = pathlib.Path(self._base_dir, docker_context).resolve()
  File "/usr/local/Cellar/[email protected]/3.8.10/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pathlib.py", line 1042, in __new__
    self = cls._from_parts(args, init=False)
  File "/usr/local/Cellar/[email protected]/3.8.10/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pathlib.py", line 683, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/usr/local/Cellar/[email protected]/3.8.10/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pathlib.py", line 667, in _parse_args
    a = os.fspath(a)

As a result, it is currently not possible to deploy Docker-packed Lambda functions, without building the underlying image using SAM, which is, in my opinion, very limiting (e.g., inability to share ECR registries & images among an Organization, inability to use Docker images that require a specific build workflow -passing secrets using buildkit, environment specific args-...)

I did find a workaround, tricking SAM into skipping the build of a PackageType: Image Lambda, by setting the Code.S3Bucket property to an empty value, but I believe this to be very hack-y:

  # A working hack to skip the build of a Image Lambda function
  Function:
    Type: AWS::Lambda::Function
    Properties:
      PackageType: Image
      Code:
        S3Bucket: !Ref AWS::NoValue
        ImageUri: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/function:latest

Proposal

  • Similarly to Zip packaged lambdas, check whether or not the ImageUri property of a AWS::Serverless::Function, or Code.ImageUri property of a AWS::Lambda::Function is a valid ECR URL before attempting to locally build said function. This could be done by reusing a function in the package.ecr_utils module here.
  • Show the user a proper warning when skipping the build of Docker lambda images.

Things to consider:

  1. Will this require any updates to the SAM Spec

Additional Details

A PR should follow soon with a workaround proposal.

alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 6, 2021
@c2tarun c2tarun added the type/feature Feature request label Jun 7, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 10, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 10, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 21, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 21, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 22, 2021
@qingchm
Copy link
Contributor

qingchm commented Jun 24, 2021

Going to review the PR ;)

alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 25, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 29, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 29, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jun 29, 2021
moelasmar pushed a commit to moelasmar/aws-sam-cli that referenced this issue Jul 1, 2021
@alexisfacques
Copy link
Contributor Author

Hello there @qingchm @sriram-mv, regarding this issue and PR#2935, came across some integrations problems; didn't want to open a new issue.

Description:

As discussed above, the proposed solution fixes problems occurring in build command, skipping the build of ECR images when said images are already valid ecr-registry images.

  # SAM will not attempt to build this Lambda
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/function:latest
% sam build -t template.yml
The resource AWS::Serverless::Function 'Function' has specified ECR registry image for ImageUri. It will not be built and SAM CLI does not support invoking it locally.

Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided

However, attempting to deploy such a template will likely output a validation error, ...and the user will still be prompt with an image repository argument using the --guided context, not none of the --image-repository or --image-repositories options are set:

Steps to reproduce:

  • Example of template:
AWSTemplateFormatVersion: 2010-09-09

Resources:

  # SAM will not attempt to build this Lambda
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/function:latest

Without specifying any option, or samconfig.toml

  • sam build
  • sam build --guided

Observed result:

Respectively,

% sam deploy                    
Usage: sam deploy [OPTIONS]
Try 'sam deploy -h' for help.

Error: Missing option '--image-repository' or '--image-repositories'
% sam deploy --guided

Configuring SAM deploy
======================

	Looking for config file [samconfig.toml] :  Not found

	Setting default arguments for 'sam deploy'
	=========================================
	Stack Name [sam-app]: 
	AWS Region [eu-west-1]: 
	Image Repository for Function:

Expected result:

Both the validation and the prompt should be ignored for this kind of functions.

Issue as been traced to image_repository_validation.py, and guided_context.py

Proposal:

Will open a PR shortly regarding this integration issue. As SamFunctionProvider._extract_functions() now only returns a list packageable functions, simplest way to do so would be to resolve template function resources using this provider, rather than the commands/_utils/template utilities.

alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jul 1, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jul 1, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jul 1, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jul 2, 2021
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jul 2, 2021
* fix lambda ECR image build/validation/deploy:
- change guided context to only prompt image-repository option for 
buildable, packageable lambda images;
- change CLI 'image-repository' 'image-repositories' option validation 
to only check the template for buildable, packageable lambda images.
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Jul 2, 2021
* fix lambda ECR image build/validation/deploy:
- change guided context to only prompt image-repository option for 
buildable, packageable lambda images;
- change CLI 'image-repository' 'image-repositories' option validation 
to only check the template for buildable, packageable lambda images.
c2tarun added a commit that referenced this issue Jul 14, 2021
* chore: Increase awareness of same file warning during package (#2946)

* chore: increase awareness of same file warning during package

* fix formatting & grammar

Co-authored-by: Mathieu Grandis <[email protected]>

* fix: Allow the base64Encoded field in REST Api, skip validation of unknown fields and validate missing statusCode for Http Api (#2941)

* fix API Gateway emulator:
 - skip validating the non allowed fields for Http Api Gateway, as it always skip the unknown fields
 - add base64Encoded as an allowed field for Rest Api gateway
 - base64 decoding will be always done for Http API gateway if the lambda response isBase64Encoded is true regardless the content-type
 - validate if statusCode is missing in case of Http API, and payload version 1.0

* - accept "true", "True", "false", "False" as valid isBase64Encoded values.
- Validate on other isBase64Encoded Values
- add more integration && unit test cases

* fix lint && black issues

* use smaller image to test Base64 response

* fix: pass copy of environment variables for keeping cache valid (#2943)

* fix: pass copy of environment variables for keeping cache valid

* add integ tests

* update docs

* make black happy

Co-authored-by: Qingchuan Ma <[email protected]>

* fix: Skip build of Docker image if ImageUri is a valid ECR URL (#2934) (#2935)

* Add condition to managed bucket policy (#2999)

* Update appveyor.yml to do docker login on both dockerhub and Public ECR (#3005) (#3006)

Co-authored-by: Wing Fung Lau <[email protected]>

* chore: bump version to 1.25.0 (#3007)

Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>

* temp: reduce python testing matrix (#3008)

* temp: disable testing against python 3.8, and enabled 3.7 (#3009)

* temp: disable testing against python 3.8, and enabled 3.7

* temp: disable testing against python 3.8, and enabled 3.7 & 3.6

* fix: enable all runtimes in python testing matrix (#3011)

* revert: enable all runtimes in python testing matrix

* fix indentation for yml

* chore: update to aws-sam-translator 1.37.0 (#3019)

* chore: bump version to 1.26.0 (#3020)

* chore: Improved --resolve-s3 option documentation and deployment without s3 error messages (#2983)

* Improve documentation on --resolve-s3 option and improve s3 failure messages

* Changed indentation for integration test on s3 error message

* Fixed a typo in description

* Improve spacing on help text for resolve-s3 option

Co-authored-by: Mehmet Nuri Deveci <[email protected]>
Co-authored-by: Mathieu Grandis <[email protected]>
Co-authored-by: Mohamed Elasmar <[email protected]>
Co-authored-by: Qingchuan Ma <[email protected]>
Co-authored-by: Alexis Facques <[email protected]>
Co-authored-by: Wing Fung Lau <[email protected]>
Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>
hawflau added a commit that referenced this issue Jul 21, 2021
* Added ecr_bootstrap

* Added companion_stack_manager

* Added Companion Stack Manager

* Added update_companion_stack

* Updated companion_stack_builder File Name

* Formatted with Black

* Updated get_unreferenced_repos

* Updated guided_context to Use Companion Stack

* Added Delete Auto Create ECR Repo Prompt

* Updated prompt_image_repository Flow

* Added --resolve-image-repos

* Addressed Some of Pylint Issues

* Updated Helper Text

* Updated Comments

* Fixed Typing

* Removed Unused Imports

* Updated Unit Tests

* Updated UX and Fixed Windows ANSI

* Updated Unit Tests

* Fixed Import Order

* Added Ignore Import Check

* Added Integration Tests

* Updated help text.

Co-authored-by: Chris Rehn <[email protected]>

* Added Comments for Name Generation

* Updated Image Option Validator

* Updated CompanionStackBuilder to Use Dict instead of String

* Fixed Argument Ordering

* Added Mapping Information to Help Text

* Updated delete_unreferenced_repos Doc String

* Updated sync_repos Doc String

* Added Justification for ECR Repo Physical ID

* Refactored to be Less Coupled

* Refactored for prompt_specify_repos

* Fixed Unit Test

* Moved WaiterConfig Out of Methods

* Updated Typing

* Updated Managed S3 Template to be Dict

* Fixed Typo

* Added Comments for _save_image_repositories

* Fixed Pylint Issue

* Added Missing Check for unreferenced_repo_uris

* Updated Variable Name

* Fixed Typo

* Updated Windows Check to Use platform.system()

* Updated update_companion_stack Logic

* Fixed Comment Typo

* Fixed Typos

* Fixed Test Name

* Added methods for cf and s3 files and init UI

* Added unit tests for utils methods and s3_uploader

* Removed s3_bucket and s3_prefix click options

* chore: Increase awareness of same file warning during package (#2946)

* chore: increase awareness of same file warning during package

* fix formatting & grammar

Co-authored-by: Mathieu Grandis <[email protected]>

* fix: Allow the base64Encoded field in REST Api, skip validation of unknown fields and validate missing statusCode for Http Api (#2941)

* fix API Gateway emulator:
 - skip validating the non allowed fields for Http Api Gateway, as it always skip the unknown fields
 - add base64Encoded as an allowed field for Rest Api gateway
 - base64 decoding will be always done for Http API gateway if the lambda response isBase64Encoded is true regardless the content-type
 - validate if statusCode is missing in case of Http API, and payload version 1.0

* - accept "true", "True", "false", "False" as valid isBase64Encoded values.
- Validate on other isBase64Encoded Values
- add more integration && unit test cases

* fix lint && black issues

* use smaller image to test Base64 response

* Fixed lint errors and added few unit tests

* Make black happy

* Added methods for deleting template artifacts

* Wait method added for delete cf api

* fix: pass copy of environment variables for keeping cache valid (#2943)

* fix: pass copy of environment variables for keeping cache valid

* add integ tests

* update docs

* make black happy

Co-authored-by: Qingchuan Ma <[email protected]>

* Added LOG statements

* Added and updated changes based on CR

* Fixed the unit tests in artifact_exporter.py

* Update HELP_TEXT in delete/command.py

Co-authored-by: Chris Rehn <[email protected]>

* fix: Skip build of Docker image if ImageUri is a valid ECR URL (#2934) (#2935)

* Updated code based on Chris' comments

* Added condition for resources that have deletionpolicy specified

* Small changes and fixes based on the comments

* Add condition to managed bucket policy (#2999)

* Removed region prompt

* Update appveyor.yml to do docker login on both dockerhub and Public ECR (#3005) (#3006)

Co-authored-by: Wing Fung Lau <[email protected]>

* chore: bump version to 1.25.0 (#3007)

Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>

* temp: reduce python testing matrix (#3008)

* temp: disable testing against python 3.8, and enabled 3.7 (#3009)

* temp: disable testing against python 3.8, and enabled 3.7

* temp: disable testing against python 3.8, and enabled 3.7 & 3.6

* fix: enable all runtimes in python testing matrix (#3011)

* revert: enable all runtimes in python testing matrix

* fix indentation for yml

* Added unit tests for ecr delete method and typing for methods

* Reformatted delete_context and added option to skip user prompts

* Removed return type from artifact_exporter for delete method

* Added unit tests for artifact_exporter and delete_context

* Added more unit tests for delete_context and artifact_exporter

* chore: update to aws-sam-translator 1.37.0 (#3019)

* chore: bump version to 1.26.0 (#3020)

* Added more unit tests for delete_context and artifact_exporter

* Added docs and comments for artifact_exporter and ecr_uploader

* Added log statements in delete_context and some updates in unit tests

* Changed force to no-prompts  and updated ecr delete method error handling

* chore: Improved --resolve-s3 option documentation and deployment without s3 error messages (#2983)

* Improve documentation on --resolve-s3 option and improve s3 failure messages

* Changed indentation for integration test on s3 error message

* Fixed a typo in description

* Improve spacing on help text for resolve-s3 option

* Created a separate function for parsing ecr url in ecr_uploader

* Reformatted Template class init to pass template_str and init template_dict

* Changed how s3 url is obtained for resource_zip edge-case: aws:glue:job

* Fixed edge case where resource artifact points to a path style url

* run Make black

* Made the parse s3 url funcs protected and defined a parent method and modified delete method for ResourceImageDict

* Changed parse_ecr_url function name to parse_image_url

* Defined UI for auto ecr deleton and method calls from companion_stack_manager

* Added code for deleting repos from companion stack

* Handle json templates deployed to cf

* Changed the order of companion stack and ecr repos deletion

* Handle delete_failed status for ecr companion stack and changed delete_stack to include retain_resources

* Reformatted auto ecr deletion to handle deleting companion stack as input stack name

* Fixed and added more unit tests for delete_context

* When region is not provided, prompt user to enter profile and region

* Removed region prompt and reading it from current session or assign a default instead

* Added ECR resource in packageable_resources and refactored ecr companion stack deletion

* Added log statements and unit tests for ECRResource

* Better error handling for ecr delete_artifact

* Revert "Merge remote-tracking branch 'wiltons-repo/feat/auto-ecr' into auto-ecr-delete"

This reverts commit 0e159c2, reversing
changes made to 1675b7e.

* Added unit test for delete ecr repository

* Fixed small string nits and added docstring for ECRResource

* Added some unit tests for s3_uploader, ecr_uploader and delete_context

* Updated to context refresh only when region and profile have non None values and removed unused class variable in delete_context

* Added unit test for ResourceImageDict class methods

Co-authored-by: Wilton Wang <[email protected]>
Co-authored-by: Chris Rehn <[email protected]>
Co-authored-by: Mathieu Grandis <[email protected]>
Co-authored-by: Mehmet Nuri Deveci <[email protected]>
Co-authored-by: Mohamed Elasmar <[email protected]>
Co-authored-by: Qingchuan Ma <[email protected]>
Co-authored-by: Alexis Facques <[email protected]>
Co-authored-by: Wing Fung Lau <[email protected]>
Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>
moelasmar added a commit that referenced this issue Jul 22, 2021
* Added ecr_bootstrap

* Added companion_stack_manager

* Added Companion Stack Manager

* Added update_companion_stack

* Updated companion_stack_builder File Name

* Formatted with Black

* Updated get_unreferenced_repos

* Updated guided_context to Use Companion Stack

* Added Delete Auto Create ECR Repo Prompt

* Updated prompt_image_repository Flow

* Added --resolve-image-repos

* Addressed Some of Pylint Issues

* Updated Helper Text

* Updated Comments

* Fixed Typing

* Removed Unused Imports

* Updated Unit Tests

* Updated UX and Fixed Windows ANSI

* Updated Unit Tests

* Fixed Import Order

* Added Ignore Import Check

* Added Integration Tests

* Updated help text.

Co-authored-by: Chris Rehn <[email protected]>

* Added Comments for Name Generation

* Updated Image Option Validator

* Updated CompanionStackBuilder to Use Dict instead of String

* Fixed Argument Ordering

* Added Mapping Information to Help Text

* Updated delete_unreferenced_repos Doc String

* Updated sync_repos Doc String

* Added Justification for ECR Repo Physical ID

* Refactored to be Less Coupled

* Refactored for prompt_specify_repos

* Fixed Unit Test

* Moved WaiterConfig Out of Methods

* Updated Typing

* Updated Managed S3 Template to be Dict

* Fixed Typo

* Added Comments for _save_image_repositories

* Fixed Pylint Issue

* Added Missing Check for unreferenced_repo_uris

* Updated Variable Name

* Fixed Typo

* Updated Windows Check to Use platform.system()

* Updated update_companion_stack Logic

* Fixed Comment Typo

* Fixed Typos

* Fixed Test Name

* Added methods for cf and s3 files and init UI

* Added unit tests for utils methods and s3_uploader

* Removed s3_bucket and s3_prefix click options

* chore: Increase awareness of same file warning during package (#2946)

* chore: increase awareness of same file warning during package

* fix formatting & grammar

Co-authored-by: Mathieu Grandis <[email protected]>

* fix: Allow the base64Encoded field in REST Api, skip validation of unknown fields and validate missing statusCode for Http Api (#2941)

* fix API Gateway emulator:
 - skip validating the non allowed fields for Http Api Gateway, as it always skip the unknown fields
 - add base64Encoded as an allowed field for Rest Api gateway
 - base64 decoding will be always done for Http API gateway if the lambda response isBase64Encoded is true regardless the content-type
 - validate if statusCode is missing in case of Http API, and payload version 1.0

* - accept "true", "True", "false", "False" as valid isBase64Encoded values.
- Validate on other isBase64Encoded Values
- add more integration && unit test cases

* fix lint && black issues

* use smaller image to test Base64 response

* Fixed lint errors and added few unit tests

* Make black happy

* Added methods for deleting template artifacts

* Wait method added for delete cf api

* fix: pass copy of environment variables for keeping cache valid (#2943)

* fix: pass copy of environment variables for keeping cache valid

* add integ tests

* update docs

* make black happy

Co-authored-by: Qingchuan Ma <[email protected]>

* Added LOG statements

* Added and updated changes based on CR

* Fixed the unit tests in artifact_exporter.py

* Update HELP_TEXT in delete/command.py

Co-authored-by: Chris Rehn <[email protected]>

* fix: Skip build of Docker image if ImageUri is a valid ECR URL (#2934) (#2935)

* Updated code based on Chris' comments

* Added condition for resources that have deletionpolicy specified

* Small changes and fixes based on the comments

* Add condition to managed bucket policy (#2999)

* Removed region prompt

* Update appveyor.yml to do docker login on both dockerhub and Public ECR (#3005) (#3006)

Co-authored-by: Wing Fung Lau <[email protected]>

* chore: bump version to 1.25.0 (#3007)

Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>

* temp: reduce python testing matrix (#3008)

* temp: disable testing against python 3.8, and enabled 3.7 (#3009)

* temp: disable testing against python 3.8, and enabled 3.7

* temp: disable testing against python 3.8, and enabled 3.7 & 3.6

* fix: enable all runtimes in python testing matrix (#3011)

* revert: enable all runtimes in python testing matrix

* fix indentation for yml

* Added unit tests for ecr delete method and typing for methods

* Reformatted delete_context and added option to skip user prompts

* Removed return type from artifact_exporter for delete method

* Added unit tests for artifact_exporter and delete_context

* Added more unit tests for delete_context and artifact_exporter

* chore: update to aws-sam-translator 1.37.0 (#3019)

* chore: bump version to 1.26.0 (#3020)

* Added more unit tests for delete_context and artifact_exporter

* Added docs and comments for artifact_exporter and ecr_uploader

* Added log statements in delete_context and some updates in unit tests

* Changed force to no-prompts  and updated ecr delete method error handling

* chore: Improved --resolve-s3 option documentation and deployment without s3 error messages (#2983)

* Improve documentation on --resolve-s3 option and improve s3 failure messages

* Changed indentation for integration test on s3 error message

* Fixed a typo in description

* Improve spacing on help text for resolve-s3 option

* Created a separate function for parsing ecr url in ecr_uploader

* Reformatted Template class init to pass template_str and init template_dict

* Changed how s3 url is obtained for resource_zip edge-case: aws:glue:job

* Fixed edge case where resource artifact points to a path style url

* run Make black

* Made the parse s3 url funcs protected and defined a parent method and modified delete method for ResourceImageDict

* Changed parse_ecr_url function name to parse_image_url

* Defined UI for auto ecr deleton and method calls from companion_stack_manager

* Added code for deleting repos from companion stack

* Handle json templates deployed to cf

* Changed the order of companion stack and ecr repos deletion

* Handle delete_failed status for ecr companion stack and changed delete_stack to include retain_resources

* Reformatted auto ecr deletion to handle deleting companion stack as input stack name

* Fixed and added more unit tests for delete_context

* When region is not provided, prompt user to enter profile and region

* Removed region prompt and reading it from current session or assign a default instead

* Added ECR resource in packageable_resources and refactored ecr companion stack deletion

* Added log statements and unit tests for ECRResource

* Better error handling for ecr delete_artifact

* Revert "Merge remote-tracking branch 'wiltons-repo/feat/auto-ecr' into auto-ecr-delete"

This reverts commit 0e159c2, reversing
changes made to 1675b7e.

* Added unit test for delete ecr repository

* Fixed small string nits and added docstring for ECRResource

* Added some unit tests for s3_uploader, ecr_uploader and delete_context

* feat: Add SAM Pipeline commands (#3085)

* sam pipeline bootstrap (#2811)

* two-stages-pipeline plugin

* typos

* add docstring

* make mypy happy

* removing swap file

* delete the two_stages_pipeline plugin as the pipeline-bootstrap command took over its responsibility

* remove 'get_template_function_runtimes' function as the decision is made to not process the SAM template during pipeline init which was the only place we use the function

* sam pipeline bootstrap command

* move the pipelineconfig.toml file to .aws-sam

* UX - rewriting

Co-authored-by: Chris Rehn <[email protected]>

* UX improvements

* make black happy

* apply review comments

* UX - rewriting

Co-authored-by: Chris Rehn <[email protected]>

* refactor

* Apply review comments

* use python way of array elements assignments

* Update samcli/lib/pipeline/bootstrap/stage.py

Co-authored-by: _sam <[email protected]>

* apply review comments

* typo

* read using utf-8

* create and user a safe version of the save_config method

* apply review comments

* rename _get_command_name to _get_command_names

* don't save generated ARNs for now, will save during init

* Revert "don't save generated ARNs for now, will save during init"

This reverts commit d184e16.

* Notify the user to rotate periodically rotate the IAM credentials

* typo

* Use AES instead of KMS for S3 SSE

* rename Ecr to ECR and Iam to IAM

* Grant lambda service explicit permissions to thhe ECR instead of relying on giving this permissions on ad-hoc while creating the container images

Co-authored-by: Chris Rehn <[email protected]>
Co-authored-by: _sam <[email protected]>

* sam pipeline init command (#2831)

* sam pipeline init command

* apply review comments

* apply review comments

* display a message that we have successfully created the pipeline configuration file(s).

* doc typo

* Let 'sam pipeline init'  prefills pipeline's infrastructure resources… (#2894)

* Let 'sam pipeline init'  prefills pipeline's infrastructure resources' values from 'sam pipeline bootstrap'  results.

* save bootstrapped sateg region

* make black happy

* exclude non-dict keys from samconfig.get_env_names method.

* Rename the pipeline 'Stage' concept to 'Environment' (#2908)

* Rename the pipeline 'Stage' concept to 'Environment'

* typo

* Rename --environment-name argument to --environment

* Sam pipelines ux rename ecr repo to image repository (#2910)

* Rename ecr-repo to image-repository

* UT Fixes

* typo

* typo

* feat: Support creating pipeline files directly into . without hooks (#2911)

* feat: Support creating pipeline files directly into . without hooks

* Integration test for pipeline init and pipeline bootstrap (#2841)

* Expose Environment._get_stack_name for integ test to predict stack name

* Add integ test for pipeline bootstrap

* Add init integ test

* small UX improvements: (#2914)

* small UX improvements:
1. show a message when the user cancels a bootstrapping command.
2. Don't prompt for CI/CD provider or provider templates if there is only one choice.
3. Make PipelineFileAlreadyExistsError a UserError.
4. use the Colored class instead of fg='color' when prompting a colored message.
5. Fix a bug where we were not allowing empty response for not required questions.

* Fix Integration Test: We now don't ask the user to select a provider's pipeline template if there is only one

* Add docs for PipelineFileAlreadyExistsError

* make black happy

* Sam pipelines s3 security (#2975)

* Deny non https requests for the artifacts S3 bucket

* enable bucket serverside logging

* add integration tests for artifacts bucket SSL-only requests and access logging

* typo

* Ensure the ArtifactsLoggingBucket denies non ssl requests (#2976)

* Sam pipelines ux round 3 (#2979)

* rename customer facing message 'CI/CD provider' to 'CI/CD system'

* add a note about what 'Environment Name' is during the pipeline bootstrap guided context

* Apply suggestions from code review

typo

Co-authored-by: Chris Rehn <[email protected]>

Co-authored-by: Chris Rehn <[email protected]>

* let pipeline IAM user assume only IAM roles tagged with Role=pipeline-execution-role (#2982)

* Adding AWS_ prefix to displayed out. (#2993)

Co-authored-by: Tarun Mall <[email protected]>

* Add region to pipeline bootstrap interactive flow (#2997)

* Ask AWS region in bootstrap interactive flow

* Read default region from boto session first

* Fix a unit test

* Inform write to pipelineconfig.toml at the end of bootstrap (#3002)

* Print info about pipelineconfig.toml after resources are bootstrapped

* Update samcli/commands/pipeline/bootstrap/cli.py

Co-authored-by: Chris Rehn <[email protected]>

Co-authored-by: Chris Rehn <[email protected]>

* List detected env names in pipeline init when prompt to input the env name (#3000)

* Allow question.question can be resolved using key path

* Pass the list of env names message (environment_names_message) into pipeline init interactive flow context

* Update samcli/commands/pipeline/init/interactive_init_flow.py

Co-authored-by: Chris Rehn <[email protected]>

* Fix unit test (trigger pr builds)

* Fix integ test

* Fix integ test

Co-authored-by: Chris Rehn <[email protected]>

* Adding account id to bootstrap message. (#2998)

* Adding account id to bootstrap message.

* adding docstring

* Addressing PR comments.

* Adding unit tests.

* Fixing unit tests.

Co-authored-by: Tarun Mall <[email protected]>

* Cfn creds fix (#3014)

* Removing pipeline user creds from cfn output. This maintains same user exp.

Co-authored-by: Tarun Mall <[email protected]>

* Ux bootstrap revamp 20210706 (#3021)

* Add intro paragraph to bootstrap

* Add switch account prompt

* Revamp stage definition prompt

* Revamp existing resources prompt

* Revamp security prompt

* Allow answers to be changed later

* Add exit message for bootstrap

* Add exit message for bootstrap (1)

* Add indentation to review values

* Add "Below is the summary of the answers:"

* Sweep pylint errors

* Update unit tests

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/cli.py

Co-authored-by: Chris Rehn <[email protected]>

* Update unit tests

* Add bold to other literals

Co-authored-by: Chris Rehn <[email protected]>

* Adding account condition for CFN execution role. (#3027)

Co-authored-by: Tarun Mall <[email protected]>

* pipeline UX revamp 20210707 (#3031)

* Allow running bootstrap inside pipeline init

* Select account credential source within bootstrap

* Add bootstrap decorations within pipeline init

* Removing ip range option from bootstrap. (#3036)

* Removing ip range option from bootstrap.

* Fixing unit test from UX PR.

Co-authored-by: Tarun Mall <[email protected]>

* Fix toml file incorrect read/write in init --bootstrap (#3037)

* Temporarily removing account fix. (#3038)

Co-authored-by: Tarun Mall <[email protected]>

* Rename environment to stage (#3040)

* Improve account source selection (#3042)

* Fixing various cosmetics UX issues with pipeline workflow. (#3046)

* Fixing credential to credentials

* Forcing text color to yellow.

* Adding new line after stage diagram.

* Adding extra line after checking bootstrap message.

* Renaming config -> configuration

* account source -> credential source

* Removing old message.

* Fixing indentation in list.

* Fixing bunch of indentation.

* fixing f string

Co-authored-by: Tarun Mall <[email protected]>

* Auto skip questions if stage detected (#3045)

* Autofill question if default value is presented

* Allow to use index to select stage names (#3051)

* Updating message when bootstrap stages are missing. (#3058)

* Updating message when bootstrap stages are missing.

* Fixing indendation

Co-authored-by: Tarun Mall <[email protected]>

* Fixing bootstrap integ tests. (#3061)

* Fixing bootstrap integ tests.

* Cleaning up some integ tests.

* Using environment variables when running integ test on CI.

* Using expression instead of full loop.

* Adding instruction to use default profile on local.

Co-authored-by: Tarun Mall <[email protected]>

* Fix bootstrap test region (#3064)

* Fix bootstrap region in integ test

* Fix regions in non-interactive mode as well

* Add more pipeline init integ test (#3065)

* Fix existing pipeline init integ test

* Add more pipeline init integ tests

* Config file bug (#3066)

* Validating config file after bootstrap stack creation.

* Validating config file after bootstrap.

Co-authored-by: Tarun Mall <[email protected]>

* Fix pipeline init integ test because of pipelineconfig file exists (#3067)

* Make stage name randomized to avoid race condition among multi canary runs (#3078)

* Load number of stages from pipeline template (#3059)

* Load number of stages from templates

* Rename variable and add debug log

* Add encoding to open()

* Allow roles with Tag aws-sam-pipeline-codebuild-service-role to assume PipelineExecutionRole (#2950)

* pipeline init UX: Ask to confirm when file exists (#3079)

* Ask to confirm overriding if files already exist, or save to another directory

* Add doc links (#3087)

* Adding accidentally removed tests back. (#3088)

Co-authored-by: Tarun Mall <[email protected]>

Co-authored-by: elbayaaa <[email protected]>
Co-authored-by: Chris Rehn <[email protected]>
Co-authored-by: Ahmed Elbayaa <[email protected]>
Co-authored-by: Tarun <[email protected]>
Co-authored-by: Tarun Mall <[email protected]>

* chore: bump aws-lambda-builder version to 1.5.0 (#3086)

* chore: update to aws-sam-translator 1.38.0 (#3073)

* Updated to context refresh only when region and profile have non None values and removed unused class variable in delete_context

* Added unit test for ResourceImageDict class methods

* ci: Update expected Jenkins file in pipeline integ test (#3090)

* chore: Refine pipeline help text and update unit test (#3091)

* Update --bucket help text

* Update --stage help text

* Update help text

* Update help text

* Update help text

* Update help text

* Update help text

* Update jenkins generated files

* Update some intro texts

* Remove trialing spaces

* Clearing pipeline integ test buckets with versioned objects. (#3094)

* Clearing pipeline integ test buckets with versioned objects.

* Fixing black formatting.

Co-authored-by: Tarun Mall <[email protected]>

* Fixing bug in bucket cleanup. (#3096)

Co-authored-by: Tarun Mall <[email protected]>

* Deleting bucket (#3097)

Co-authored-by: Tarun Mall <[email protected]>

* Revert "temp: disable testing against python 3.8, and enabled 3.7 (#3009)" (#3098)

This reverts commit fe83218.

Co-authored-by: Tarun Mall <[email protected]>

* chore: bump SAM CLI version to 1.27.0 (#3101)

* Add pipeline to pyinstaller (#3103)

* Adding pipeline to pyinstaller.

Co-authored-by: Tarun Mall <[email protected]>

Co-authored-by: Wilton Wang <[email protected]>
Co-authored-by: Chris Rehn <[email protected]>
Co-authored-by: Mathieu Grandis <[email protected]>
Co-authored-by: Mehmet Nuri Deveci <[email protected]>
Co-authored-by: Mohamed Elasmar <[email protected]>
Co-authored-by: Qingchuan Ma <[email protected]>
Co-authored-by: Alexis Facques <[email protected]>
Co-authored-by: Wing Fung Lau <[email protected]>
Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>
Co-authored-by: _sam <[email protected]>
Co-authored-by: elbayaaa <[email protected]>
Co-authored-by: Ahmed Elbayaa <[email protected]>
Co-authored-by: Tarun <[email protected]>
Co-authored-by: Tarun Mall <[email protected]>
Co-authored-by: Raymond Wang <[email protected]>
moelasmar added a commit that referenced this issue Jul 22, 2021
* chore: Increase awareness of same file warning during package (#2946)

* chore: increase awareness of same file warning during package

* fix formatting & grammar

Co-authored-by: Mathieu Grandis <[email protected]>

* fix: Allow the base64Encoded field in REST Api, skip validation of unknown fields and validate missing statusCode for Http Api (#2941)

* fix API Gateway emulator:
 - skip validating the non allowed fields for Http Api Gateway, as it always skip the unknown fields
 - add base64Encoded as an allowed field for Rest Api gateway
 - base64 decoding will be always done for Http API gateway if the lambda response isBase64Encoded is true regardless the content-type
 - validate if statusCode is missing in case of Http API, and payload version 1.0

* - accept "true", "True", "false", "False" as valid isBase64Encoded values.
- Validate on other isBase64Encoded Values
- add more integration && unit test cases

* fix lint && black issues

* use smaller image to test Base64 response

* fix: pass copy of environment variables for keeping cache valid (#2943)

* fix: pass copy of environment variables for keeping cache valid

* add integ tests

* update docs

* make black happy

Co-authored-by: Qingchuan Ma <[email protected]>

* fix: Skip build of Docker image if ImageUri is a valid ECR URL (#2934) (#2935)

* Add condition to managed bucket policy (#2999)

* Update appveyor.yml to do docker login on both dockerhub and Public ECR (#3005) (#3006)

Co-authored-by: Wing Fung Lau <[email protected]>

* chore: bump version to 1.25.0 (#3007)

Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>

* temp: reduce python testing matrix (#3008)

* temp: disable testing against python 3.8, and enabled 3.7 (#3009)

* temp: disable testing against python 3.8, and enabled 3.7

* temp: disable testing against python 3.8, and enabled 3.7 & 3.6

* fix: enable all runtimes in python testing matrix (#3011)

* revert: enable all runtimes in python testing matrix

* fix indentation for yml

* chore: update to aws-sam-translator 1.37.0 (#3019)

* chore: bump version to 1.26.0 (#3020)

* chore: Improved --resolve-s3 option documentation and deployment without s3 error messages (#2983)

* Improve documentation on --resolve-s3 option and improve s3 failure messages

* Changed indentation for integration test on s3 error message

* Fixed a typo in description

* Improve spacing on help text for resolve-s3 option

* feat: Add SAM Pipeline commands (#3085)

* sam pipeline bootstrap (#2811)

* two-stages-pipeline plugin

* typos

* add docstring

* make mypy happy

* removing swap file

* delete the two_stages_pipeline plugin as the pipeline-bootstrap command took over its responsibility

* remove 'get_template_function_runtimes' function as the decision is made to not process the SAM template during pipeline init which was the only place we use the function

* sam pipeline bootstrap command

* move the pipelineconfig.toml file to .aws-sam

* UX - rewriting

Co-authored-by: Chris Rehn <[email protected]>

* UX improvements

* make black happy

* apply review comments

* UX - rewriting

Co-authored-by: Chris Rehn <[email protected]>

* refactor

* Apply review comments

* use python way of array elements assignments

* Update samcli/lib/pipeline/bootstrap/stage.py

Co-authored-by: _sam <[email protected]>

* apply review comments

* typo

* read using utf-8

* create and user a safe version of the save_config method

* apply review comments

* rename _get_command_name to _get_command_names

* don't save generated ARNs for now, will save during init

* Revert "don't save generated ARNs for now, will save during init"

This reverts commit d184e16.

* Notify the user to rotate periodically rotate the IAM credentials

* typo

* Use AES instead of KMS for S3 SSE

* rename Ecr to ECR and Iam to IAM

* Grant lambda service explicit permissions to thhe ECR instead of relying on giving this permissions on ad-hoc while creating the container images

Co-authored-by: Chris Rehn <[email protected]>
Co-authored-by: _sam <[email protected]>

* sam pipeline init command (#2831)

* sam pipeline init command

* apply review comments

* apply review comments

* display a message that we have successfully created the pipeline configuration file(s).

* doc typo

* Let 'sam pipeline init'  prefills pipeline's infrastructure resources… (#2894)

* Let 'sam pipeline init'  prefills pipeline's infrastructure resources' values from 'sam pipeline bootstrap'  results.

* save bootstrapped sateg region

* make black happy

* exclude non-dict keys from samconfig.get_env_names method.

* Rename the pipeline 'Stage' concept to 'Environment' (#2908)

* Rename the pipeline 'Stage' concept to 'Environment'

* typo

* Rename --environment-name argument to --environment

* Sam pipelines ux rename ecr repo to image repository (#2910)

* Rename ecr-repo to image-repository

* UT Fixes

* typo

* typo

* feat: Support creating pipeline files directly into . without hooks (#2911)

* feat: Support creating pipeline files directly into . without hooks

* Integration test for pipeline init and pipeline bootstrap (#2841)

* Expose Environment._get_stack_name for integ test to predict stack name

* Add integ test for pipeline bootstrap

* Add init integ test

* small UX improvements: (#2914)

* small UX improvements:
1. show a message when the user cancels a bootstrapping command.
2. Don't prompt for CI/CD provider or provider templates if there is only one choice.
3. Make PipelineFileAlreadyExistsError a UserError.
4. use the Colored class instead of fg='color' when prompting a colored message.
5. Fix a bug where we were not allowing empty response for not required questions.

* Fix Integration Test: We now don't ask the user to select a provider's pipeline template if there is only one

* Add docs for PipelineFileAlreadyExistsError

* make black happy

* Sam pipelines s3 security (#2975)

* Deny non https requests for the artifacts S3 bucket

* enable bucket serverside logging

* add integration tests for artifacts bucket SSL-only requests and access logging

* typo

* Ensure the ArtifactsLoggingBucket denies non ssl requests (#2976)

* Sam pipelines ux round 3 (#2979)

* rename customer facing message 'CI/CD provider' to 'CI/CD system'

* add a note about what 'Environment Name' is during the pipeline bootstrap guided context

* Apply suggestions from code review

typo

Co-authored-by: Chris Rehn <[email protected]>

Co-authored-by: Chris Rehn <[email protected]>

* let pipeline IAM user assume only IAM roles tagged with Role=pipeline-execution-role (#2982)

* Adding AWS_ prefix to displayed out. (#2993)

Co-authored-by: Tarun Mall <[email protected]>

* Add region to pipeline bootstrap interactive flow (#2997)

* Ask AWS region in bootstrap interactive flow

* Read default region from boto session first

* Fix a unit test

* Inform write to pipelineconfig.toml at the end of bootstrap (#3002)

* Print info about pipelineconfig.toml after resources are bootstrapped

* Update samcli/commands/pipeline/bootstrap/cli.py

Co-authored-by: Chris Rehn <[email protected]>

Co-authored-by: Chris Rehn <[email protected]>

* List detected env names in pipeline init when prompt to input the env name (#3000)

* Allow question.question can be resolved using key path

* Pass the list of env names message (environment_names_message) into pipeline init interactive flow context

* Update samcli/commands/pipeline/init/interactive_init_flow.py

Co-authored-by: Chris Rehn <[email protected]>

* Fix unit test (trigger pr builds)

* Fix integ test

* Fix integ test

Co-authored-by: Chris Rehn <[email protected]>

* Adding account id to bootstrap message. (#2998)

* Adding account id to bootstrap message.

* adding docstring

* Addressing PR comments.

* Adding unit tests.

* Fixing unit tests.

Co-authored-by: Tarun Mall <[email protected]>

* Cfn creds fix (#3014)

* Removing pipeline user creds from cfn output. This maintains same user exp.

Co-authored-by: Tarun Mall <[email protected]>

* Ux bootstrap revamp 20210706 (#3021)

* Add intro paragraph to bootstrap

* Add switch account prompt

* Revamp stage definition prompt

* Revamp existing resources prompt

* Revamp security prompt

* Allow answers to be changed later

* Add exit message for bootstrap

* Add exit message for bootstrap (1)

* Add indentation to review values

* Add "Below is the summary of the answers:"

* Sweep pylint errors

* Update unit tests

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/guided_context.py

Co-authored-by: Chris Rehn <[email protected]>

* Update samcli/commands/pipeline/bootstrap/cli.py

Co-authored-by: Chris Rehn <[email protected]>

* Update unit tests

* Add bold to other literals

Co-authored-by: Chris Rehn <[email protected]>

* Adding account condition for CFN execution role. (#3027)

Co-authored-by: Tarun Mall <[email protected]>

* pipeline UX revamp 20210707 (#3031)

* Allow running bootstrap inside pipeline init

* Select account credential source within bootstrap

* Add bootstrap decorations within pipeline init

* Removing ip range option from bootstrap. (#3036)

* Removing ip range option from bootstrap.

* Fixing unit test from UX PR.

Co-authored-by: Tarun Mall <[email protected]>

* Fix toml file incorrect read/write in init --bootstrap (#3037)

* Temporarily removing account fix. (#3038)

Co-authored-by: Tarun Mall <[email protected]>

* Rename environment to stage (#3040)

* Improve account source selection (#3042)

* Fixing various cosmetics UX issues with pipeline workflow. (#3046)

* Fixing credential to credentials

* Forcing text color to yellow.

* Adding new line after stage diagram.

* Adding extra line after checking bootstrap message.

* Renaming config -> configuration

* account source -> credential source

* Removing old message.

* Fixing indentation in list.

* Fixing bunch of indentation.

* fixing f string

Co-authored-by: Tarun Mall <[email protected]>

* Auto skip questions if stage detected (#3045)

* Autofill question if default value is presented

* Allow to use index to select stage names (#3051)

* Updating message when bootstrap stages are missing. (#3058)

* Updating message when bootstrap stages are missing.

* Fixing indendation

Co-authored-by: Tarun Mall <[email protected]>

* Fixing bootstrap integ tests. (#3061)

* Fixing bootstrap integ tests.

* Cleaning up some integ tests.

* Using environment variables when running integ test on CI.

* Using expression instead of full loop.

* Adding instruction to use default profile on local.

Co-authored-by: Tarun Mall <[email protected]>

* Fix bootstrap test region (#3064)

* Fix bootstrap region in integ test

* Fix regions in non-interactive mode as well

* Add more pipeline init integ test (#3065)

* Fix existing pipeline init integ test

* Add more pipeline init integ tests

* Config file bug (#3066)

* Validating config file after bootstrap stack creation.

* Validating config file after bootstrap.

Co-authored-by: Tarun Mall <[email protected]>

* Fix pipeline init integ test because of pipelineconfig file exists (#3067)

* Make stage name randomized to avoid race condition among multi canary runs (#3078)

* Load number of stages from pipeline template (#3059)

* Load number of stages from templates

* Rename variable and add debug log

* Add encoding to open()

* Allow roles with Tag aws-sam-pipeline-codebuild-service-role to assume PipelineExecutionRole (#2950)

* pipeline init UX: Ask to confirm when file exists (#3079)

* Ask to confirm overriding if files already exist, or save to another directory

* Add doc links (#3087)

* Adding accidentally removed tests back. (#3088)

Co-authored-by: Tarun Mall <[email protected]>

Co-authored-by: elbayaaa <[email protected]>
Co-authored-by: Chris Rehn <[email protected]>
Co-authored-by: Ahmed Elbayaa <[email protected]>
Co-authored-by: Tarun <[email protected]>
Co-authored-by: Tarun Mall <[email protected]>

* chore: bump aws-lambda-builder version to 1.5.0 (#3086)

* chore: update to aws-sam-translator 1.38.0 (#3073)

* ci: Update expected Jenkins file in pipeline integ test (#3090)

* chore: Refine pipeline help text and update unit test (#3091)

* Update --bucket help text

* Update --stage help text

* Update help text

* Update help text

* Update help text

* Update help text

* Update help text

* Update jenkins generated files

* Update some intro texts

* Remove trialing spaces

* Clearing pipeline integ test buckets with versioned objects. (#3094)

* Clearing pipeline integ test buckets with versioned objects.

* Fixing black formatting.

Co-authored-by: Tarun Mall <[email protected]>

* Fixing bug in bucket cleanup. (#3096)

Co-authored-by: Tarun Mall <[email protected]>

* Deleting bucket (#3097)

Co-authored-by: Tarun Mall <[email protected]>

* Revert "temp: disable testing against python 3.8, and enabled 3.7 (#3009)" (#3098)

This reverts commit fe83218.

Co-authored-by: Tarun Mall <[email protected]>

* chore: bump SAM CLI version to 1.27.0 (#3101)

* Add pipeline to pyinstaller (#3103)

* Adding pipeline to pyinstaller.

Co-authored-by: Tarun Mall <[email protected]>

Co-authored-by: Mehmet Nuri Deveci <[email protected]>
Co-authored-by: Mathieu Grandis <[email protected]>
Co-authored-by: Qingchuan Ma <[email protected]>
Co-authored-by: Alexis Facques <[email protected]>
Co-authored-by: Wing Fung Lau <[email protected]>
Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>
Co-authored-by: _sam <[email protected]>
Co-authored-by: elbayaaa <[email protected]>
Co-authored-by: Chris Rehn <[email protected]>
Co-authored-by: Ahmed Elbayaa <[email protected]>
Co-authored-by: Tarun <[email protected]>
Co-authored-by: Tarun Mall <[email protected]>
Co-authored-by: Raymond Wang <[email protected]>
moelasmar added a commit to moelasmar/aws-sam-cli that referenced this issue Jul 22, 2021
* Added ecr_bootstrap

* Added companion_stack_manager

* Added Companion Stack Manager

* Added update_companion_stack

* Updated companion_stack_builder File Name

* Formatted with Black

* Updated get_unreferenced_repos

* Updated guided_context to Use Companion Stack

* Added Delete Auto Create ECR Repo Prompt

* Updated prompt_image_repository Flow

* Added --resolve-image-repos

* Addressed Some of Pylint Issues

* Updated Helper Text

* Updated Comments

* Fixed Typing

* Removed Unused Imports

* Updated Unit Tests

* Updated UX and Fixed Windows ANSI

* Updated Unit Tests

* Fixed Import Order

* Added Ignore Import Check

* Added Integration Tests

* Updated help text.

Co-authored-by: Chris Rehn <[email protected]>

* Added Comments for Name Generation

* Updated Image Option Validator

* Updated CompanionStackBuilder to Use Dict instead of String

* Fixed Argument Ordering

* Added Mapping Information to Help Text

* Updated delete_unreferenced_repos Doc String

* Updated sync_repos Doc String

* Added Justification for ECR Repo Physical ID

* Refactored to be Less Coupled

* Refactored for prompt_specify_repos

* Fixed Unit Test

* Moved WaiterConfig Out of Methods

* Updated Typing

* Updated Managed S3 Template to be Dict

* Fixed Typo

* Added Comments for _save_image_repositories

* Fixed Pylint Issue

* Added Missing Check for unreferenced_repo_uris

* Updated Variable Name

* Fixed Typo

* Updated Windows Check to Use platform.system()

* Updated update_companion_stack Logic

* Fixed Comment Typo

* Fixed Typos

* Fixed Test Name

* Added methods for cf and s3 files and init UI

* Added unit tests for utils methods and s3_uploader

* Removed s3_bucket and s3_prefix click options

* chore: Increase awareness of same file warning during package (aws#2946)

* chore: increase awareness of same file warning during package

* fix formatting & grammar

Co-authored-by: Mathieu Grandis <[email protected]>

* fix: Allow the base64Encoded field in REST Api, skip validation of unknown fields and validate missing statusCode for Http Api (aws#2941)

* fix API Gateway emulator:
 - skip validating the non allowed fields for Http Api Gateway, as it always skip the unknown fields
 - add base64Encoded as an allowed field for Rest Api gateway
 - base64 decoding will be always done for Http API gateway if the lambda response isBase64Encoded is true regardless the content-type
 - validate if statusCode is missing in case of Http API, and payload version 1.0

* - accept "true", "True", "false", "False" as valid isBase64Encoded values.
- Validate on other isBase64Encoded Values
- add more integration && unit test cases

* fix lint && black issues

* use smaller image to test Base64 response

* Fixed lint errors and added few unit tests

* Make black happy

* Added methods for deleting template artifacts

* Wait method added for delete cf api

* fix: pass copy of environment variables for keeping cache valid (aws#2943)

* fix: pass copy of environment variables for keeping cache valid

* add integ tests

* update docs

* make black happy

Co-authored-by: Qingchuan Ma <[email protected]>

* Added LOG statements

* Added and updated changes based on CR

* Fixed the unit tests in artifact_exporter.py

* Update HELP_TEXT in delete/command.py

Co-authored-by: Chris Rehn <[email protected]>

* fix: Skip build of Docker image if ImageUri is a valid ECR URL (aws#2934) (aws#2935)

* Updated code based on Chris' comments

* Added condition for resources that have deletionpolicy specified

* Small changes and fixes based on the comments

* Add condition to managed bucket policy (aws#2999)

* Removed region prompt

* Update appveyor.yml to do docker login on both dockerhub and Public ECR (aws#3005) (aws#3006)

Co-authored-by: Wing Fung Lau <[email protected]>

* chore: bump version to 1.25.0 (aws#3007)

Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>

* temp: reduce python testing matrix (aws#3008)

* temp: disable testing against python 3.8, and enabled 3.7 (aws#3009)

* temp: disable testing against python 3.8, and enabled 3.7

* temp: disable testing against python 3.8, and enabled 3.7 & 3.6

* fix: enable all runtimes in python testing matrix (aws#3011)

* revert: enable all runtimes in python testing matrix

* fix indentation for yml

* Added unit tests for ecr delete method and typing for methods

* Reformatted delete_context and added option to skip user prompts

* Removed return type from artifact_exporter for delete method

* Added unit tests for artifact_exporter and delete_context

* Added more unit tests for delete_context and artifact_exporter

* chore: update to aws-sam-translator 1.37.0 (aws#3019)

* chore: bump version to 1.26.0 (aws#3020)

* Added more unit tests for delete_context and artifact_exporter

* Added docs and comments for artifact_exporter and ecr_uploader

* Added log statements in delete_context and some updates in unit tests

* Changed force to no-prompts  and updated ecr delete method error handling

* chore: Improved --resolve-s3 option documentation and deployment without s3 error messages (aws#2983)

* Improve documentation on --resolve-s3 option and improve s3 failure messages

* Changed indentation for integration test on s3 error message

* Fixed a typo in description

* Improve spacing on help text for resolve-s3 option

* Created a separate function for parsing ecr url in ecr_uploader

* Reformatted Template class init to pass template_str and init template_dict

* Changed how s3 url is obtained for resource_zip edge-case: aws:glue:job

* Fixed edge case where resource artifact points to a path style url

* run Make black

* Made the parse s3 url funcs protected and defined a parent method and modified delete method for ResourceImageDict

* Changed parse_ecr_url function name to parse_image_url

* Defined UI for auto ecr deleton and method calls from companion_stack_manager

* Added code for deleting repos from companion stack

* Handle json templates deployed to cf

* Changed the order of companion stack and ecr repos deletion

* Handle delete_failed status for ecr companion stack and changed delete_stack to include retain_resources

* Reformatted auto ecr deletion to handle deleting companion stack as input stack name

* Fixed and added more unit tests for delete_context

* When region is not provided, prompt user to enter profile and region

* Removed region prompt and reading it from current session or assign a default instead

* Added ECR resource in packageable_resources and refactored ecr companion stack deletion

* Added log statements and unit tests for ECRResource

* Better error handling for ecr delete_artifact

* Revert "Merge remote-tracking branch 'wiltons-repo/feat/auto-ecr' into auto-ecr-delete"

This reverts commit 0e159c2, reversing
changes made to 1675b7e.

* Added unit test for delete ecr repository

* Fixed small string nits and added docstring for ECRResource

* Added some unit tests for s3_uploader, ecr_uploader and delete_context

* Updated to context refresh only when region and profile have non None values and removed unused class variable in delete_context

* Added unit test for ResourceImageDict class methods

Co-authored-by: Wilton Wang <[email protected]>
Co-authored-by: Chris Rehn <[email protected]>
Co-authored-by: Mathieu Grandis <[email protected]>
Co-authored-by: Mehmet Nuri Deveci <[email protected]>
Co-authored-by: Mohamed Elasmar <[email protected]>
Co-authored-by: Qingchuan Ma <[email protected]>
Co-authored-by: Alexis Facques <[email protected]>
Co-authored-by: Wing Fung Lau <[email protected]>
Co-authored-by: Sriram Madapusi Vasudevan <[email protected]>
@ccmoose
Copy link

ccmoose commented Apr 18, 2022

Found a reference to this issue in some old notes, and I noticed PR #2935 (#2935) that fixes this issue.

Unless I'm missing something, that means this issue can be resolved, right?

@matlik
Copy link

matlik commented Apr 22, 2022

I'm not convinced this issue is fully resolved. In fact, the solution implemented in #2935 has introduced a regression for us.

This issue requests that the following isn't built:

  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/function:latest

However, why would this preclude SAM from being able to invoke the lambda locally if the docker image already exists in the local image cache?

We are using SAM to integration test lambdas that are built from multiple projects. There is no build or deploy being performed, just a local test of the lambda functions and the step function state machine that wires it all together. But now we are getting the following error when things used to work fine:
The resource AWS::Serverless::Function 'SetupFunction' has specified ECR registry image for ImageUri. It will not be built and SAM CLI does not support invoking it locally.

@jp-reejig
Copy link

jp-reejig commented Sep 28, 2022

/+ 1

@taylorsmithgg
Copy link

I'm not convinced this issue is fully resolved. In fact, the solution implemented in #2935 has introduced a regression for us.

This issue requests that the following isn't built:

  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: 123456789012.dkr.ecr.eu-west-1.amazonaws.com/function:latest

However, why would this preclude SAM from being able to invoke the lambda locally if the docker image already exists in the local image cache?

We are using SAM to integration test lambdas that are built from multiple projects. There is no build or deploy being performed, just a local test of the lambda functions and the step function state machine that wires it all together. But now we are getting the following error when things used to work fine: The resource AWS::Serverless::Function 'SetupFunction' has specified ECR registry image for ImageUri. It will not be built and SAM CLI does not support invoking it locally.

100x this. We have no means to test using sam, have to do it manually with docker.

@taylorsmithgg
Copy link

taylorsmithgg commented Aug 3, 2023

We did find a work around by "tricking" sam:

  FunctionName:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub "function-name-${Stage}"
      Timeout: 900
      MemorySize: 768
      PackageType: Image
      Role: arn:aws:iam::<aws-account-id>:role/lambda
#      Exclude ECR from the name because local invoke breaks
#      ImageUri: !Sub "<aws-account-id>.dkr.ecr.<aws-region>.amazonaws.com/org/image-name:${ImageTag}"
      ImageUri: !Sub "image-name"
      ImageConfig:
        Command:
          - com.MyMainClass::handleRequest
      Environment:
        Variables:
          VAR1: !Ref StateMachineV2

alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Aug 8, 2023
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Aug 8, 2023
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Aug 8, 2023
@alexisfacques
Copy link
Contributor Author

Well it's been a while.
So, let me give you a quick update on what's been happening with the issue.

To add some clarity, the changes I proposed in #2935 were to let us skip the build of Lambda functions with valid ECR registry locations as CodeUri / Code parameters. It's like using a valid S3 URI that skips the local artifacts build - and life saver if you’re building big Docker images, as I was at the time.

However, there was a bit of a hiccup with sam deploy --guided (Guided Context) and sam deploy commands, throwing this error: Error: Missing option '--image-repositories', '--image-repository', '--resolve-image-repos' even when all the IMAGE Lambda functions in the templates were valid image URIs (thus not requiring the --image-repository option to be set).

One workaround is set the --image-repository option to an empty string. I proposed a fix back then, but unfortunately, it turned out to be quite complex and couldn't keep up with all the new code and unit tests to make it through validation

Fast forward 2 years, the sam deploy —guided (Guided Context) issue seems to be resolved now; however, we still have a problem with the deploy options validation lingering around. I've resubmitted a much simpler PR (#5729) that should finally put an end to this issue. It makes use of a the _is_all_image_funcs_provided method, since introduced, to skip the option requirement if no "buildable" IMAGE lambdas are specified within a template.

I see no particular side effect to this change, but will happily discuss the matter further if needed.
@moelasmar @mildaniel

@taylorsmithgg
Copy link

@alexisfacques

The resource AWS::Serverless::Function 'SetupFunction' has specified ECR registry image for ImageUri. It will not be built and SAM CLI does not support invoking it locally.

What about sam local invoke?

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2023

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

@alexisfacques
Copy link
Contributor Author

@alexisfacques

The resource AWS::Serverless::Function 'SetupFunction' has specified ECR registry image for ImageUri. It will not be built and SAM CLI does not support invoking it locally.

What about sam local invoke?

Hi @taylorsmithgg, if I've grasped your earlier messages correctly, you're utilizing the desired ECR location within your Code settings, which does indeed prevent local execution.

To follow up on your issue, are you aiming for SAM to manage the build and deployment of this image? Or is your intention solely to run it locally?

If your expectation involves the build process, please note that the Code parameter doesn't hold significance within SAM when dealing with IMAGE Lambdas. It essentially serves as the local image name on your system, and it will be retagged with the ECR registry name (as specified in your SAM configuration file or command-line argument) along with the DockerImageTag metadata. Modifying the Code parameter to any other value should resolve the issue.

In my view, this behavior aligns with norms, similar to ZIP Lambdas. For instance, specifying a valid S3 location in the Code property skips the build phase entirely, thus preventing local invocations. On the other hand, targeting a local path triggers the build process, with the local path being substituted by SAM's designated S3 location upon deployment.

However, if your intention is for SAM to retrieve the image to facilitate local invocation, this introduces an entirely new feature (albeit super intriguing imo); but we should consider extending this functionality to ZIP Lambdas as well (assuming the AWS credentials provided possess adequate permissions to fetch S3 data).

@taylorsmithgg
Copy link

taylorsmithgg commented Aug 8, 2023

@alexisfacques We use jib to build our Java lambdas in lieu of sam for many reasons.

However, if your intention is for SAM to retrieve the image to facilitate local invocation, this introduces an entirely new feature (albeit super intriguing imo); but we should consider extending this functionality to ZIP Lambdas as well (assuming the AWS credentials provided possess adequate permissions to fetch S3 data).

This is accurate and what is intended. Essentially we migrated a few projects and now have to manually run several steps to stand up a local invocation that should be easily solvable by sam local invoke

It doesn't seem like there should be the same restrictions in place for docker builds as zips since you can arbitrarily retrieve images from any source available. (local, ecr, dockerhub, etc.)

In the above comment, it seems that this was working at some point, at least in a rough format before the fix.

@alexisfacques
Copy link
Contributor Author

alexisfacques commented Aug 8, 2023

@alexisfacques We use jib to build our Java lambdas in lieu of sam for many reasons.

However, if your intention is for SAM to retrieve the image to facilitate local invocation, this introduces an entirely new feature (albeit super intriguing imo); but we should consider extending this functionality to ZIP Lambdas as well (assuming the AWS credentials provided possess adequate permissions to fetch S3 data).

This is accurate and what is intended. Essentially we migrated a few projects and now have to manually run several steps to stand up a local invocation that should be easily solvable by sam local invoke

It doesn't seem like there should be the same restrictions in place for docker builds as zips since you can arbitrarily retrieve images from any source available. (local, ecr, dockerhub, etc.)

In the above comment, it seems that this was working at some point, at least in a rough format before the fix.

Ahhh I get it now.

Indeed, as long as the image is appropriately tagged within your local Docker environment, I'd personally see no reason why SAM would not be able to run it locally.

FYI, this matter can be traced back to this specific line within the local invoke execution process. Ultimately, this code relies on this instruction found within the component responsible for listing (valid) Lambda functions in a template, shared between both the local invoke and deploy commands.

I would leave it to @mildaniel & @moelasmar to decide on that matter, but I believe we could easily get around that by altering how this method (called by deploy) would handle returning Lambda functions declarations: get_all() would return deployable functions, while self.functions would return all functions but s3 located zip ones. Shouldn't be any other side effects in regards to how the Provider object is used.

alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Aug 10, 2023
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Aug 10, 2023
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Aug 17, 2023
alexisfacques added a commit to alexisfacques/aws-sam-cli that referenced this issue Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests