Support for --profile argument when deploying to AWS
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
Implement Support for --profile Argument in Serverless Deploy
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
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.
bashnpm install -g serverless - 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.
yamlcustom: awsProfile: ${opt:profile, 'default'} - 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.
javascriptconst AWS = require('aws-sdk'); AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: process.argv[3] }); - 4
Test Deployment with Profile
Run the deployment command using the --profile argument to verify that it correctly utilizes the specified AWS profile.
bashserverless 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
Alex Chen
2450 rep