0

I am using the AWS SDK for PHP in a PHP script. In the SDK, I am using the Parameter Store integration and retrieving the value of a Parameter to be used in the script. I am able to to retrieve the parameter, but am receiving it as a JSON object. I am trying to parse the JSON object to where I am only receiving the value of the parameter from the JSON object. Below is the PHP script I am running and the JSON object it returns. Note, it has a tip on how to retrieve data, but I am unsure how to apply. Any advice on how to extract the value only would be helpful.

PHP Script

<?php
require 'aws-autoloader.php';
use Aws\Ssm\SsmClient;
use Aws\Exception\AwsException;

try {
    // Create SSM Client
    $ssmClient = new SsmClient([
            'region' => 'us-east-2',
            'version' => 'latest'
    ]);

    $tempCred = $ssmClient->getParameter([
            'Name' => 'tempCred',
            'WithDecryption' => true
    ]);
} catch (SsmException $e) {
        echo $e->getMessage() . "\n";
}

   echo "Temp Cred is $tempCred";
?>

Script Output

php index.php
Temp Cred is Model Data
----------
Data can be retrieved from the model object using the get() method of the
model (e.g., `$result->get($key)`) or "accessing the result like an
associative array (e.g. `$result['key']`). You can also execute JMESPath
expressions on the result data using the search() method.

{
    "Parameter": {
        "Name": "tempCred",
        "Type": "SecureString",
        "Value": "xxxxxxxx",
        "Version": 1,
        "LastModifiedDate": "2022-10-28T21:27:35+00:00",
        "ARN": "arn:aws:ssm:us-east-2:xxxxxxxxxx:parameter\/tempCred",
        "DataType": "text"
    },
    "@metadata": {
        "statusCode": 200,
        "effectiveUri": "https:\/\/ssm.us-east-2.amazonaws.com",
        "headers": {
            "server": "Server",
            "date": "Sun, 30 Oct 2022 22:28:00 GMT",
            "content-type": "application\/x-amz-json-1.1",
            "content-length": "211",
            "connection": "keep-alive",
            "x-amzn-requestid": "ec4ac9f4-b7b6-43a4-af4f-1be03b16b5fd"
        },
        "transferStats": {
            "http": [
                []
            ]
        }
    }
}
Dave Michaels
  • 847
  • 1
  • 19
  • 51
  • Does this answer your question? [How to extract and access data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-to-extract-and-access-data-from-json-with-php) – M. Eriksson Oct 30 '22 at 22:45

0 Answers0