Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get parameters in Parameter Store aws

I'm approacching now to aws.

I'm trying to store parameter in the Parameter Store of my EC2 instance, and I would get them for put in an environment variable in the AfterInstall step of Codedeploy. The deploy works, but I can't get the parameter anyway.

I tried to follow this tutorial https://aws.amazon.com/it/blogs/mt/use-parameter-store-to-securely-access-secrets-and-config-data-in-aws-codedeploy/.

I created the policy "ParameterStorePolicy" as follow:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "ssm:DescribeParameters"
        ],
        "Resource": "*"
    },
    {
        "Effect": "Allow",
        "Action": [
            "ssm:GetParameters"
        ],
        "Resource": [
            "arn:aws:ssm:us-east-2:<myId>:parameter/MySecureSQLPassword"
        ]
    },
    {
        "Effect": "Allow",
        "Action": [
            "kms:Decrypt"
        ],
        "Resource": "arn:aws:kms:us-east-2:<myId>:alias/aws/ssm"
    }
]}

I attached the policy to the "CodeDeployServiceRole" that has also attached the "AWSCodeDeployRole".

Finally in my script "Afterinstall.sh" I wrote the following code:

cd /home/ubuntu/pypi
export PIPPO=$(aws ssm get-parameters --region us-east-2 --names 
MySecureSQLPassword --with-decryption --query Parameters[0].Value)
echo $PIPPO >testPippo.txt

The result is a void testPippo.txt file.

Can anyone say me what I wrong?

Thank you

like image 828
Simone Biffi Avatar asked Sep 11 '17 12:09

Simone Biffi


1 Answers

Check that the "ParameterStorePolicy" IAM policy is attached to the EC2 instance profile of the instance you are deploying to.

To confirm whether the instance has the correct permissions you can do either of the following:

  1. Run that CLI command directly on the instance and confirm the value is decrypted:

aws ssm get-parameters --region us-east-2 --names MySecureSQLPassword --with-decryption --query Parameters[0].Value

  1. Log into the AWS Console then go to https://policysim.aws.amazon.com/home/index.jsp?#roles find your EC2 instance role and simulate that role's access to that parameter.
like image 144
JimmyL Avatar answered Nov 18 '22 15:11

JimmyL