AWS Code Sample

Accesses a secret resource on the core.

# Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You # may not use this file except in compliance with the License. A copy of # the License is located at # # # # or in the "license" file accompanying this file. This file is # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. # # This sample is used in the AWS IoT Greengrass Developer Guide: # # import greengrasssdk # Create SDK clients. secrets_client = greengrasssdk.client('secretsmanager') message_client = greengrasssdk.client('iot-data') message = '' # This handler is called when the function is invoked. # It uses the 'secretsmanager' client to get the value of the test secret using the secret name. # The test secret is a text type, so the SDK returns a string. # For binary secret values, the SDK returns a base64-encoded string. def function_handler(event, context): response = secrets_client.get_secret_value(SecretId='greengrass-TestSecret') secret_value = response.get('SecretString') if secret_value is None: message = 'Failed to retrieve secret.' else: message = 'Success! Retrieved secret.' message_client.publish(topic='secrets/output', payload=message) print('published: ' + message)

Sample Details

Service: greengrass

Last tested: 2019-01-03

Author: AWS

Type: full-example

On this page: