Replies: 2 comments 5 replies
-
This is great. A few points:
|
Beta Was this translation helpful? Give feedback.
4 replies
-
Love it! It would be great if SAM can print the response to stdout, and relevant CloudWatch logs (perhaps traces) for the function execution to stderr. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
#2550 - Related GitHub issue
Summary
SAM CLI supports invoking Lambda functions locally using the
sam local invoke
command during development. But it does not support invoking and testing the functions deployed to the cloud. The SAM CLIsync
command can be used to accelerate the development process by quickly deploying the local changes to the cloud as the changes are made, but users have to rely on either AWS console or AWS CLI to test the new changes. This proposal outlines the design of a new SAM CLI command to interact with the cloud resources and verify any new changes deployed.Proposed Design
We are working on adding a new SAM CLI command which will help interact with the AWS resources on cloud and print the response on the console. The general idea is the command will use the provided resource logical-id and stack-name to look up the physical-id from the deployed stack and call the boto3 API. The command will support a payload option which can be used to send data to the resource. Payload could be a different parameter in the API definition for each resource. For instance, Lambda Function payload is the JSON provided as input. For SQS, payload is the Entries parameter in the API definition. This payload can be passed in as a string, an existing file path, or be read from stdin.
The proposed AWS resources and the boto3 APIs this new command will call are as follows :
Lambda Function
: Invokes the function by calling eitherLambda.Client.invoke
orLambda.Client.invoke_with_response_stream
boto3 API based on the function configuration in the template. ThePayload
parameter in the API definition can be passed as payload to the command.Step Functions
: Starts the step function execution by calling theSFN.Client.start_execution
boto3 API. Theinput
parameter in the API definition can be passed as payload to the command.SQS
: Sends messages to the Queue by calling theSQS.Client.send_message_batch
boto3 API. TheEntries
parameter in the API definition can be passed as payload to the command.Kinesis
: Writes data records in the Kinesis data stream by calling theKinesis.Client.put_records
boto3 API. TheRecords
parameter in the API definition can be passed as payload to the command.This will help developers validate their changes are working as expected on the cloud using SAM CLI and also help improve the developer experience while using
sam sync
. The command will allow developers to invoke or send an event to the resource using the logical-id defined in the SAM template instead of finding the physical-id from the cloud themselves. If the stack-name option is provided, the command will use the resource-id as the logical-id to search for the resource.If no stack-name option is provided and the resource physical-id is provided as resource-id, the command will find the resource information from the CloudFormation template and call the resource boto3 API.
The command will also support a tail option for tailing CloudWatch logs and XRay traces which will run
sam logs --tail --include-traces
after the invocation is completed.Developers will also be able to save their invoke configuration in the samconfig.toml file.
The
sam local generate-event
command can also be used to create payloads for different resource types and these payloads can be used to invoke the Lambda Function on cloud using this new command.Example for starting a Step Function execution using the remote invoke command:
Example for sending a message to a SQS Queue using the remote invoke command:
Example for sending data to a Kinesis stream using the remote invoke command:
We are looking for general comments on the following topics as well as thoughts regarding the new SAM CLI command:
sam remote invoke
command while developing Serverless applications using SAM CLI?--parameter Qualifier:MyQualifier --parameter InvocationType:Event
.We encourage the community to provide feedback and suggestions for the proposed design and how SAM CLI can help improve the developer experience.
Beta Was this translation helpful? Give feedback.
All reactions