Step 2.3: Upload the deployment package (create the Lambda function) - Amazon ElastiCache

Step 2.3: Upload the deployment package (create the Lambda function)

In this step, you create the Lambda function (AccessMemcached) using the create-function AWS CLI command.

From the project directory containing your deployment package .zip file, run the following Lambda CLI create-function command.

For the role option, use the ARN of the execution role you created in step 2.2. For the vpc-config enter comma separated lists of your default VPC's subnets and your default VPC's security group ID. You can find these values in the Amazon VPC console. To find your default VPC's subnets, choose Your VPCs, then choose your AWS account's default VPC. To find the security group for this VPC, under Security, choose Security groups. Ensure that you have the us-east-1 region selected.

For Linux, macOS, or Unix:

aws lambda create-function \ --function-name AccessMemcached \ --region us-east-1 \ --zip-file fileb://my_deployment_package.zip \ --role arn:aws:iam::123456789012:role/lambda-vpc-execution-role \ --handler app.lambda_handler \ --runtime python3.11 \ --timeout 30 \ --vpc-config SubnetIds=comma-separated-vpc-subnet-ids,SecurityGroupIds=default-security-group-id \

For Windows:

aws lambda create-function ^ --function-name AccessMemcached ^ --region us-east-1 ^ --zip-file fileb://path-to/my_deployment_package.zip ^ --role arn:aws:iam::123456789012:role/lambda-vpc-execution-role ^ --handler app.lambda_handler ^ --runtime python3.11 ^ --timeout 30 ^ --vpc-config SubnetIds=comma-separated-vpc-subnet-ids,SecurityGroupIds=default-security-group-id ^

Optionally, you can upload the .zip file to an Amazon S3 bucket in the same AWS region, and then specify the bucket and object name in the preceding command. You need to replace the --zip-file parameter with the --code parameter, as shown following:

--code S3Bucket=bucket-name,S3Key=zip-file-object-key

You can also create the Lambda function using the AWS Lambda console. When creating the function, choose a VPC for the Lambda and then select the subnets and security groups from the provided fields.

Next Step

Step 3: Test the Lambda function