FG
💻 Software☁️ Cloud & DevOpsAmazon

Support for --profile argument when deploying to AWS

Fresh5 days ago
Mar 14, 20260 views
Confidence Score78%
78%

Problem

Feature Request: it should be possible to run `serverless deploy --profile production` to use the production AWS profile. At the moment this has to be set through environment variables Benefits: - being able to easily switch profiles to deploy with

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Implement Support for --profile Argument in Serverless Deploy

Medium Risk

The current implementation of the serverless framework does not support the --profile argument for AWS deployments, requiring users to set AWS credentials through environment variables. This limitation restricts flexibility in managing multiple AWS profiles for different environments.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Update Serverless Framework

    Ensure you are using the latest version of the Serverless Framework, as this feature may have been added in a recent update.

    bash
    npm install -g serverless
  2. 2

    Modify Serverless Configuration

    In your serverless.yml configuration file, add a custom command to handle the --profile argument. This will allow the framework to recognize and utilize the specified AWS profile during deployment.

    yaml
    custom:
      awsProfile: ${opt:profile, 'default'}
  3. 3

    Implement Command Handling

    Modify the deploy command in your serverless framework to accept the --profile argument and pass it to the AWS SDK. This may involve editing the serverless CLI code if not natively supported.

    javascript
    const AWS = require('aws-sdk');
    AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: process.argv[3] });
  4. 4

    Test Deployment with Profile

    Run the deployment command using the --profile argument to verify that it correctly utilizes the specified AWS profile.

    bash
    serverless deploy --profile production

Validation

To confirm the fix worked, execute the deployment command with the --profile argument and check the AWS resources created. Ensure they correspond to the specified profile's configuration. Additionally, verify that the deployment does not require setting environment variables for AWS credentials.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

serverlesslambdaaws