AWS_PROFILE not working with aws cli - aws-cli

I have the aws cli installed on my macbook. I updated the version last week and since then it seems like it ignores the AWS_PROFILE environment variable? Has anyone encountered this? I have to add --profile to every statement now to make it go towards the profile I prefer.
Does anyone know what could be wrong or how I should troubleshoot it?

As per this link: AWS CLI environment variables Precedence
If AWS_PROFILE environment variable is set and the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are set, then the credentials provided by AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY will override the credentials located in the profile provided by AWS_PROFILE.
You have to unset both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and set AWS_PROFILE instead then it should work correctly.
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
export AWS_PROFILE=[profile-name-here]

This looks like a bug to me.
Check my setup when I have nothing set for profile:
15278-gmcdaid:~ gmcdaid$ aws configure list
Name Value Type Location
---- ----- ---- --------
profile <not set> None None
Now, set the env var:
15278-gmcdaid:~ gmcdaid$ export AWS_PROFILE=foo
Check setup again:
15278-gmcdaid:~ gmcdaid$ aws configure list
Name Value Type Location
---- ----- ---- --------
profile foo manual --profile
You can see that when AWS_PROFILE is set, the cli is set to use the manual switch for the profile, not the env var.
I installed the aws-cli around the same time you make this post.

I was only setting the AWS_PROFILE as a shell variable and not as a environment variable. After setting is as an environment variable everything worked as expected.

Just re-state in another words and clean commands:
Run set | grep AWS, if you see any credentials there then AWS_PROFILE will be ignored
If you set the variable just as
AWS_PROFILE=boo
it won't work. Export it instead:
export AWS_PROFILE=boo

Related

How to create an elasticbeanstalk environment through boto3 setting a keypair name

If you uses the AWS console or even the command line, you won't get any issue in setting a default keypair to your Elasticbeanstalk environment.
But you do if using boto3.
Surprisingly, there's no any single mention about setting a keypair in the official boto3 documentation for elasticbeanstalk: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elasticbeanstalk.html.
Tried also to create a zip file containing the most basic files to make a simple website works. And supposedly, I can set a keypair name in the .elasticbeanstalk/config.yml". I did in this way:
branch-defaults:
default:
environment: app10-env
group_suffix: null
global:
application_name: app10
branch: null
default_ec2_keyname: main4
default_platform: PHP 7.4 running on 64bit Amazon Linux 2
default_region: us-east-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: null
repository: null
sc: null
workspace_type: null
Yes, the "main4" exists in my AWS account. But creating an environment to my application with a zip containing it, it seems that it have no effect at all. After my environment has sucessfully deployed, I can check afterwards through console and see that have no keypair setted to environment. I need to go to a further step on console to set the keypair and await a new environment deployiment to perform the update.
Is there a real issue with the boto3 elasticbeanstalk when dealing with environment keypairs or I am doing something wrong?
I would set the OptionSettings when calling create_environment or include the keyname in the .ebextensions. Boto3 is not reading the EB CLI default config you are using i guess.
Refs
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elasticbeanstalk.html#ElasticBeanstalk.Client.create_environment
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-configuration-methods-before.html
Option to set
Namespace: aws:autoscaling:launchconfiguration
Option Names: IamInstanceProfile, EC2KeyName, InstanceType
The response of #f7o is not accurate, but helped to solve the problem.
There's no option for setting an keypair using "create_environment" command from boto3 client. Tried to use a "EC2KeyName", but it returned an exception of invalid value.
But using the "ebextensions" do the work. If someone else are interested in do the same task that I am, so everything that is needed to do is create a folder called ".ebextensions" with a file called "customkey.config" (the file name can be anything, but must be suffixed with .config), and with the following content:
option_settings:
- namespace: aws:autoscaling:launchconfiguration
option_name: EC2KeyName
value: <your_keypair_name>

How to use gitlab CI environment variables in fastlane fastfile?

I am currently using a .env file to get environment variables in FASTFILE, but now I am trying to automate the fastlane using GitLab CI/CD.
Since the .env file which has all the keys can not be pushed to the branch I have to declare all the .env or the environment variables in the GitLab runner's environment variable.
I want to know how can I use the GitLab runners's environment variable in my fastfile.
lane :build_staging do |options|
environment_variable(set: { 'ENVFILE' => '.env.staging' }) // I want to use the GitLab environment variable
clean
gradle(task: options[:task], build_type: 'Staging', project_dir: 'android/')
end
In Settings > Variables, you can define the whole file as a variable with a specified scope :
In your gitlab-ci, you would use it by specifying the variable name (in my example $ENV_FILE) and the scope using stage keyword in your job :
build:
stage: staging
script:
# do your work here
You can find more info in the documentation for variable file type and scope.

Cloud9 does not expose bash_profile exports in nodejs lambda

I have a Cloud9 environment spun up and have modified my ~/.bash_profile to export a value at the end of the file.
export foo="hello world"
I run . ~/.bash_profile and then echo $foo and I see hello world output in the terminal.
I then created a NodeJS Lambda with API Gateway. I run the API Gateway locally in Cloud 9 and attempt to read the environment variables
console.log(process.env)
I see a list of variables available to me that AWS has defined. My export is not listed there however. Since I will be using environment variables when my Lambda is deployed, I want to test it with environment variables defined in the Cloud9 environment.
Is there something specific I have to do in order to get the Lambda to read my .bash_profile exports?
AWS Cloud9's Lambda plugin is backed by SAM Local, which uses Docker: https://github.com/awslabs/aws-sam-cli . By default, this means that the ~/.bash_profile file is not used by Lambda; you'll want to load this in manually.
Please see Using the AWS Serverless Application Model (AWS SAM) article that describes how to work with environment variables in SAM (so also in cloud9).
In summary - put environment variables into the template.yaml file (present in the root folder of your app) like below:
Properties:
.... # tons of other properties here, add yours at the end
Environment:
Variables:
MY_ENV_VARIABLE: 'This is my awesome env variable value'

botocore.exceptions.ProfileNotFound: The config profile (default) could not be found

I'm facing issue while export CSV from pandas datafram to S3, getting below error:
The config profile (default) could not be found: ProfileNotFound
botocore.exceptions.ProfileNotFound: The config profile (default) could not be found
Below aws cli setup in my local:
config :
[default]
region = us-west-1
credentials :
[default]
aws_secret_access_key =
aws_access_key_id =
Please help, thanks in advance
Thanks.
I had the same problem (for another application) and the only way I found to “fix” it was to create a new profile in my ~/.aws/config file.
[profile mynewprofile]
aws_access_key_id = XXXXXX
aws_secret_access_key = XXXXXX
Then I modificated the script calling my default profile to mynewprofile.
This probably won't apply to most people but I had the same error. I had set AWS_PROFILE as a permanent system environment variable on my Windows machine... and forgot. If your os has AWS_PROFILE set somewhere, you might see this error message.
AWS_PROFILE
Specifies the name of the AWS CLI profile with the credentials and options to use. This can be the name of a profile
stored in a credentials or config file, or the value default to use
the default profile.
If defined, this environment variable overrides the behavior of using the profile named [default] in the configuration file. You can
override this environment variable by using the --profile command line
parameter.
AWS Article

Systemd service configuration using environment variable

How do i set the MemoryLimit using environment variable
I have tried set MemoryLimit field by using the variable MY_LIMIT like this,
The Service configuration:
[Unit]
Description=Blabla
[Service]
Environment="MY_LIMIT=1024"
MemoryLimit=$MY_LIMIT
ExecStart=script.sh
But this doesnt seems to work
As we see that
sudo systemctl show myservice
Show that the MemoryLimit is a assigned with this value instead
MemoryLimit=18446744073709551615
systemd has an Environment directive which sets environment variables for executed processes. [source][1]
So your MY_LIMIT won't get interpreted when set in MemoryLimit.
Also MemoryLimit is deprecated, use MemoryMax= instead. [source][2]
So what you should set is: MemoryMax=1024M

Resources