You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to quickly share how I am running sidecar/lambdas for my local development in case it's of use to anyone else in the future.
1. Install AWS SAM CLI
AWS SAM CLI lets us emulate AWS serverless functions right on our local machine. Install the AWS SAM CLI by following the instructions in the link below:
In your Lambda function folder (for instance, /resources/lambda), create a template.yaml file. This file tells AWS SAM how to handle the Lambda function locally. Here's a simple example, you can add additional functions as required:
AWSTemplateFormatVersion: 2010-09-09Description: >- sc-localTransform:
- AWS::Serverless-2016-10-31Resources:
MyFunctionName:
Type: AWS::Serverless::FunctionProperties:
FunctionName: 'sc-app-local-function-name:active'# Replace this with your function name in AWS. Make sure you append :activeHandler: index.myFunctionNameRuntime: nodejs18.xArchitectures:
- x86_64MemorySize: 512Timeout: 30
3. Run Lambda Functions Locally
Now comes the exciting part! From within your /resources/lambda directory, run the following command to start your Lambda functions locally:
sam local start-lambda
This command fires up the local Lambda environment, allowing you to test your functions without the need to deploy them to AWS or have an internet connection.
4. Configure a Custom Service Provider
To customize certain aspects of the Sidecar package specifically for local development, we'll need to override a few classes.
Create the following files in your app
Services/Sidecar/AwsClientConfiguration.php
<?phpnamespaceApp\Services\Sidecar;
// Override the AWS config to set the endpoint. If you are using Laravel Sail you will need to use `host.docker.internal` to access the `localhost` on your machineclassAwsClientConfiguration {
publicfunctiongetConfiguration()
{
$config = (new \Hammerstone\Sidecar\Clients\Configurations\AwsClientConfiguration())->getConfiguration();
$config['endpoint'] = 'http://host.docker.internal:3001';
return$config;
}
}
Services/Sidecar/LambdaClient.php
<?phpnamespaceApp\Services\Sidecar;
useAws\Result;
// We need to override the `LogType` param. Local lambda only supports `None`classLambdaClientextends \Hammerstone\Sidecar\Clients\LambdaClient {
publicfunctioninvoke(array$args = []): Result
{
$args['LogType'] = 'None';
returnparent::invoke($args);
}
}
We'll use a custom service provider to ensure these classes are used only during local development. Create the following file:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First off just want to say, sidecar is awesome!
I wanted to quickly share how I am running sidecar/lambdas for my local development in case it's of use to anyone else in the future.
1. Install AWS SAM CLI
AWS SAM CLI lets us emulate AWS serverless functions right on our local machine. Install the AWS SAM CLI by following the instructions in the link below:
2. Create a SAM template.yaml
In your Lambda function folder (for instance,
/resources/lambda
), create atemplate.yaml
file. This file tells AWS SAM how to handle the Lambda function locally. Here's a simple example, you can add additional functions as required:3. Run Lambda Functions Locally
Now comes the exciting part! From within your /resources/lambda directory, run the following command to start your Lambda functions locally:
This command fires up the local Lambda environment, allowing you to test your functions without the need to deploy them to AWS or have an internet connection.
4. Configure a Custom Service Provider
To customize certain aspects of the Sidecar package specifically for local development, we'll need to override a few classes.
Create the following files in your app
Services/Sidecar/AwsClientConfiguration.php
Services/Sidecar/LambdaClient.php
We'll use a custom service provider to ensure these classes are used only during local development. Create the following file:
app/Providers/SidecarServiceProvider.php
5. Add the New Service Provider
Finally, make use of the custom service provider. Inside your
config/app.php
file, locate the 'providers' array, and add the following line:That's it!
Now you can run your Sidecar/Lambda functions locally!
Beta Was this translation helpful? Give feedback.
All reactions