Skip to content

Commit

Permalink
Merge pull request #5396 from aws/develop
Browse files Browse the repository at this point in the history
chore: merge develop to master
  • Loading branch information
mndeveci authored Jun 21, 2023
2 parents f5a3a2b + 94adeeb commit 8c9dbeb
Show file tree
Hide file tree
Showing 37 changed files with 711 additions and 84 deletions.
4 changes: 2 additions & 2 deletions appveyor-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ environment:

install:
# AppVeyor's apt-get cache might be outdated, and the package could potentially be 404.
- sh: "sudo apt-get update"
- sh: "sudo apt-get update --allow-releaseinfo-change"

- sh: "gvm use go1.19"
- sh: "echo $PATH"
Expand Down Expand Up @@ -87,7 +87,7 @@ install:
- sh: "sudo apt install -y jq"

# install Terraform
- sh: "sudo apt update"
- sh: "sudo apt update --allow-releaseinfo-change"
- sh: "TER_VER=`curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | grep tag_name | cut -d: -f2 | tr -d \\\"\\,\\v | awk '{$1=$1};1'`"
- sh: "wget https://releases.hashicorp.com/terraform/${TER_VER}/terraform_${TER_VER}_linux_amd64.zip -P /tmp"
- sh: "sudo unzip -d /opt/terraform /tmp/terraform_${TER_VER}_linux_amd64.zip"
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ regex!=2021.10.8
tzlocal==3.0

#Adding cfn-lint dependency for SAM validate
cfn-lint~=0.77.5
cfn-lint~=0.77.9
6 changes: 3 additions & 3 deletions requirements/reproducible-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ cffi==1.15.1 \
--hash=sha256:fa6693661a4c91757f4412306191b6dc88c1703f780c8234035eac011922bc01 \
--hash=sha256:fcd131dd944808b5bdb38e6f5b53013c5aa4f334c5cad0c72742f6eba4b73db0
# via cryptography
cfn-lint==0.77.5 \
--hash=sha256:4282d13ffe76a5dee6431b1f56e3641d87c28b1ef5be663afe7d8dbf13f28bdb \
--hash=sha256:b5126dffb834078a71341090d49669046076c09196f0d2bdca68dbace1bf357a
cfn-lint==0.77.9 \
--hash=sha256:7c1e631b723b521234d92d4081934291b256dba28d723ddb7ff105215fe40020 \
--hash=sha256:f95b503f7465ee1f2f89ddf32289ea03a517f08c366bb8e6a5d6773a11e5a1aa
# via aws-sam-cli (setup.py)
chardet==5.1.0 \
--hash=sha256:0d62712b956bc154f85fb0a266e2a3c5913c2967e00348701b32411d6def31e5 \
Expand Down
6 changes: 3 additions & 3 deletions requirements/reproducible-mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ cffi==1.15.1 \
--hash=sha256:fa6693661a4c91757f4412306191b6dc88c1703f780c8234035eac011922bc01 \
--hash=sha256:fcd131dd944808b5bdb38e6f5b53013c5aa4f334c5cad0c72742f6eba4b73db0
# via cryptography
cfn-lint==0.77.5 \
--hash=sha256:4282d13ffe76a5dee6431b1f56e3641d87c28b1ef5be663afe7d8dbf13f28bdb \
--hash=sha256:b5126dffb834078a71341090d49669046076c09196f0d2bdca68dbace1bf357a
cfn-lint==0.77.9 \
--hash=sha256:7c1e631b723b521234d92d4081934291b256dba28d723ddb7ff105215fe40020 \
--hash=sha256:f95b503f7465ee1f2f89ddf32289ea03a517f08c366bb8e6a5d6773a11e5a1aa
# via aws-sam-cli (setup.py)
chardet==5.1.0 \
--hash=sha256:0d62712b956bc154f85fb0a266e2a3c5913c2967e00348701b32411d6def31e5 \
Expand Down
2 changes: 1 addition & 1 deletion samcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
SAM CLI version
"""

__version__ = "1.87.0"
__version__ = "1.88.0"
7 changes: 6 additions & 1 deletion samcli/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"samcli.commands.pipeline.pipeline",
"samcli.commands.list.list",
"samcli.commands.docs",
# "samcli.commands.remote.remote",
"samcli.commands.remote.remote",
# We intentionally do not expose the `bootstrap` command for now. We might open it up later
# "samcli.commands.bootstrap",
]
Expand Down Expand Up @@ -173,6 +173,11 @@ def format_commands(self, ctx: click.Context, formatter: RootCommandHelpTextForm
text=SAM_CLI_COMMANDS.get("sync", ""),
extra_row_modifiers=[HighlightNewRowNameModifier()],
),
RowDefinition(
name="remote",
text=SAM_CLI_COMMANDS.get("remote", ""),
extra_row_modifiers=[HighlightNewRowNameModifier()],
),
],
)

Expand Down
1 change: 1 addition & 0 deletions samcli/cli/root/command_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"validate": "Validate an AWS SAM template.",
"build": "Build your AWS serverless function code.",
"local": "Run your AWS serverless function locally.",
"remote": "Invoke or send an event to cloud resources in your CFN stack",
"package": "Package an AWS SAM application.",
"deploy": "Deploy an AWS SAM application.",
"delete": "Delete an AWS SAM application and the artifacts created by sam deploy.",
Expand Down
4 changes: 2 additions & 2 deletions samcli/commands/remote/remote_invoke_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _populate_resource_summary(self) -> None:
see _get_from_physical_resource_id for details.
"""
if not self._stack_name and not self._resource_id:
raise InvalidRemoteInvokeParameters("Either --stack-name or --resource-id parameter should be provided")
raise InvalidRemoteInvokeParameters("Either --stack-name option or resource_id argument should be provided")

try:
if not self._resource_id:
Expand Down Expand Up @@ -162,7 +162,7 @@ def _get_single_resource_from_stack(self) -> CloudFormationResourceSummary:
if len(resource_summaries) > 1:
raise AmbiguousResourceForRemoteInvoke(
f"{self._stack_name} contains more than one resource that could be used with remote invoke, "
f"please provide --resource-id to resolve ambiguity."
f"please provide resource_id argument to resolve ambiguity."
)

# fail if no resource summary found with given types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def wrapped(*args, **kwargs):

def stack_name_or_resource_id_atleast_one_option_validation(func):
"""
This function validates that atleast one of --stack-name or --resource-id should is be provided
This function validates that atleast one of --stack-name option or resource_id argument should is be provided
Parameters
----------
Expand Down
1 change: 1 addition & 0 deletions samcli/lib/docs/documentation_links.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"list endpoints": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-list-endpoints.html",
"list resources": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-list-resources.html",
"deploy": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html",
"remote invoke": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-remote-invoke.html",
"package": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-package.html",
"delete": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-delete.html",
"sync": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-sync.html",
Expand Down
2 changes: 1 addition & 1 deletion samcli/lib/remote_invoke/lambda_invoke_executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def validate_action_parameters(self, parameters: dict) -> None:
"""
for parameter_key, parameter_value in parameters.items():
if parameter_key == FUNCTION_NAME:
LOG.warning("FunctionName is defined using the value provided for --resource-id option.")
LOG.warning("FunctionName is defined using the value provided for resource_id argument.")
elif parameter_key == PAYLOAD:
LOG.warning("Payload is defined using the value provided for either --event or --event-file options.")
else:
Expand Down
2 changes: 1 addition & 1 deletion samcli/runtime_config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"app_template_repo_commit": "66f4a230d1c939a0c3f7b5647710c694c3a486f7"
"app_template_repo_commit": "67f28fd83477e0e15b394f995afb33b2053b4074"
}
6 changes: 6 additions & 0 deletions tests/end_to_end/end_to_end_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from tests.integration.init.test_init_base import InitIntegBase
from tests.integration.package.package_integ_base import PackageIntegBase
from tests.integration.local.invoke.invoke_integ_base import InvokeIntegBase
from tests.integration.remote.invoke.remote_invoke_integ_base import RemoteInvokeIntegBase
from tests.integration.sync.sync_integ_base import SyncIntegBase
from tests.integration.list.stack_outputs.stack_outputs_integ_base import StackOutputsIntegBase
import logging
Expand Down Expand Up @@ -73,6 +74,11 @@ def _get_package_command(self, s3_prefix, use_json=False, output_template_file=N
def _get_local_command(self, function_name):
return InvokeIntegBase.get_command_list(function_to_invoke=function_name)

def _get_remote_invoke_command(self, stack_name, resource_id, event, output):
return RemoteInvokeIntegBase.get_command_list(
stack_name=stack_name, resource_id=resource_id, event=event, output=output
)

def _get_delete_command(self, stack_name):
return self.get_delete_command_list(stack_name=stack_name, region=self.region_name, no_prompts=True)

Expand Down
19 changes: 13 additions & 6 deletions tests/end_to_end/test_runtimes_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from tests.end_to_end.test_stages import (
DefaultInitStage,
PackageDownloadZipFunctionStage,
DefaultRemoteInvokeStage,
DefaultDeleteStage,
EndToEndBaseStage,
DefaultSyncStage,
Expand Down Expand Up @@ -47,8 +46,10 @@ def validate(self, command_result: CommandResult):

class RemoteInvokeValidator(BaseValidator):
def validate(self, command_result: CommandResult):
self.assertEqual(command_result.process.get("StatusCode"), 200)
self.assertEqual(command_result.process.get("FunctionError", ""), "")
response = json.loads(command_result.stdout.decode("utf-8"))
self.assertEqual(command_result.process.returncode, 0)
self.assertEqual(response["StatusCode"], 200)
self.assertEqual(response.get("FunctionError", ""), "")


class StackOutputsValidator(BaseValidator):
Expand All @@ -75,18 +76,21 @@ class TestHelloWorldDefaultEndToEnd(EndToEndBase):

def test_hello_world_default_workflow(self):
stack_name = self._method_to_stack_name(self.id())
function_name = "HelloWorldFunction"
event = '{"hello": "world"}'
with EndToEndTestContext(self.app_name) as e2e_context:
self.template_path = e2e_context.template_path
init_command_list = self._get_init_command(e2e_context.working_directory)
build_command_list = self.get_command_list()
deploy_command_list = self._get_deploy_command(stack_name)
stack_outputs_command_list = self._get_stack_outputs_command(stack_name)
remote_invoke_command_list = self._get_remote_invoke_command(stack_name, function_name, event, "json")
delete_command_list = self._get_delete_command(stack_name)
stages = [
DefaultInitStage(InitValidator(e2e_context), e2e_context, init_command_list, self.app_name),
EndToEndBaseStage(BuildValidator(e2e_context), e2e_context, build_command_list),
EndToEndBaseStage(BaseValidator(e2e_context), e2e_context, deploy_command_list),
DefaultRemoteInvokeStage(RemoteInvokeValidator(e2e_context), e2e_context, stack_name),
EndToEndBaseStage(RemoteInvokeValidator(e2e_context), e2e_context, remote_invoke_command_list),
EndToEndBaseStage(BaseValidator(e2e_context), e2e_context, stack_outputs_command_list),
DefaultDeleteStage(BaseValidator(e2e_context), e2e_context, delete_command_list, stack_name),
]
Expand Down Expand Up @@ -117,7 +121,7 @@ def test_hello_world_workflow(self):
package_command_list = self._get_package_command(
s3_prefix="end-to-end-package-test", use_json=True, output_template_file="packaged_template.json"
)
local_command_list = self._get_local_command("HelloWorldFunction")
local_command_list = self._get_local_command(function_name)
stages = [
DefaultInitStage(InitValidator(e2e_context), e2e_context, init_command_list, self.app_name),
EndToEndBaseStage(BuildValidator(e2e_context), e2e_context, build_command_list),
Expand All @@ -141,17 +145,20 @@ class TestHelloWorldDefaultSyncEndToEnd(EndToEndBase):
app_template = "hello-world"

def test_go_hello_world_default_workflow(self):
function_name = "HelloWorldFunction"
event = '{"hello": "world"}'
stack_name = self._method_to_stack_name(self.id())
with EndToEndTestContext(self.app_name) as e2e_context:
self.template_path = e2e_context.template_path
init_command_list = self._get_init_command(e2e_context.working_directory)
sync_command_list = self._get_sync_command(stack_name)
stack_outputs_command_list = self._get_stack_outputs_command(stack_name)
remote_invoke_command_list = self._get_remote_invoke_command(stack_name, function_name, event, "json")
delete_command_list = self._get_delete_command(stack_name)
stages = [
DefaultInitStage(InitValidator(e2e_context), e2e_context, init_command_list, self.app_name),
DefaultSyncStage(BaseValidator(e2e_context), e2e_context, sync_command_list),
DefaultRemoteInvokeStage(RemoteInvokeValidator(e2e_context), e2e_context, stack_name),
EndToEndBaseStage(RemoteInvokeValidator(e2e_context), e2e_context, remote_invoke_command_list),
EndToEndBaseStage(BaseValidator(e2e_context), e2e_context, stack_outputs_command_list),
DefaultDeleteStage(BaseValidator(e2e_context), e2e_context, delete_command_list, stack_name),
]
Expand Down
15 changes: 0 additions & 15 deletions tests/end_to_end/test_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,6 @@ def _delete_default_samconfig(self):
pass


class DefaultRemoteInvokeStage(EndToEndBaseStage):
def __init__(self, validator, test_context, stack_name):
super().__init__(validator, test_context)
self.stack_name = stack_name
self.lambda_client = boto3.client("lambda")
self.resource = boto3.resource("cloudformation")

def run_stage(self) -> CommandResult:
lambda_output = self.lambda_client.invoke(FunctionName=self._get_lambda_physical_id())
return CommandResult(lambda_output, "", "")

def _get_lambda_physical_id(self):
return self.resource.StackResource(self.stack_name, "HelloWorldFunction").physical_resource_id


class DefaultDeleteStage(EndToEndBaseStage):
def __init__(self, validator, test_context, command_list, stack_name):
super().__init__(validator, test_context, command_list)
Expand Down
46 changes: 0 additions & 46 deletions tests/integration/delete/test_delete_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,52 +436,6 @@ def test_no_prompts_no_stack_name(self):
delete_process_execute = run_command(delete_command_list)
self.assertEqual(delete_process_execute.process.returncode, 2)

@pytest.mark.flaky(reruns=3)
def test_no_prompts_no_region(self):
stack_name = self._method_to_stack_name(self.id())

delete_command_list = self.get_delete_command_list(stack_name=stack_name, no_prompts=True)
delete_process_execute = run_command(delete_command_list)
self.assertEqual(delete_process_execute.process.returncode, 2)

@parameterized.expand(
[
"aws-serverless-function.yaml",
]
)
@pytest.mark.flaky(reruns=3)
def test_delete_guided_no_stack_name_no_region(self, template_file):
template_path = self.test_data_path.joinpath(template_file)

stack_name = self._method_to_stack_name(self.id())

deploy_command_list = self.get_deploy_command_list(
template_file=template_path,
stack_name=stack_name,
capabilities="CAPABILITY_IAM",
s3_bucket=self.bucket_name,
s3_prefix=self.s3_prefix,
force_upload=True,
notification_arns=self.sns_arn,
parameter_overrides="Parameter=Clarity",
kms_key_id=self.kms_key,
no_execute_changeset=False,
tags="integ=true clarity=yes foo_bar=baz",
confirm_changeset=False,
region=self._session.region_name,
)
deploy_process_execute = run_command(deploy_command_list)

delete_command_list = self.get_delete_command_list()
delete_process_execute = run_command_with_input(delete_command_list, "{}\ny\ny\n".format(stack_name).encode())

self.assertEqual(delete_process_execute.process.returncode, 0)

try:
resp = self.cf_client.describe_stacks(StackName=stack_name)
except ClientError as ex:
self.assertIn(f"Stack with id {stack_name} does not exist", str(ex))

@parameterized.expand(
[
"aws-ecr-repository.yaml",
Expand Down
Empty file.
Empty file.
Loading

0 comments on commit 8c9dbeb

Please sign in to comment.