-
Notifications
You must be signed in to change notification settings - Fork 420
Feature request: utility function to get multiple parameters by name instead of path #1040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hey @hooverdc, thanks for creating this feature request! I believe this is best handled by your own custom wrapper, or perhaps approaching this differently.
Without knowing the number of parameters you have, their size, and how you create them, have you considered creating an aggregate parameter with multiple values? Example. This allows e2e/integ scenarios to make a single call and get everything they need, while still having separate parameters that can be useful for other purposes like deployment time. Resources:
ResourcesMapParameter:
Type: AWS::SSM::Parameter
Properties:
Name: !Sub "/${Stage}/service/trip_ingestion/test/config"
Type: String
Description: Service Map with common resources used for integ/e2e testing
Value: !Sub |
{
"MobileTripsBucket": "${MobileTripsBucket}",
"MobileTripsQueue": "${MobileTripsQueue}",
"TripIngestionFunction": "${TripIngestionFunction}",
"MobileTripsApiEndpoint": "https://${MobileTripsApi}.execute-api.${AWS::Region}.amazonaws.com/${MobileTripsApi.Stage}/trip",
"Stage": "${Stage}"
} Hope that helps! Thanks |
Hey @heitorlessa. I usually take that approach and create an aggregate SSM parameter. You can shove a lot into a single SSM parameter with base64 encoded gzip! Ultimately this isn't an issue for me. I was just hoping that Powertools supported GetParameters alongside GetParameter and GetParametersByPath out of the box. |
|
We're in a much better position to reconsider this than we were 7 months ago - I'd love to see a POC if you have the bandwidth. Back then we had to be more strict due to package size, but next month in V2, we'll reduce ~95-97% by making all dependencies optional and using boto3 available at Lambda runtime. If you do have bandwidth, please reopen and I'd appreciate a draft PR to get this going |
Adding this to our next iteration (Nov 7th-20th)! |
Shifting to this current iteration (next release in two weeks), as we've managed to finish our biggest chunk of work earlier ;) I've got a few upfront questions @hooverdc:
This would help disambiguate the implementation, tests, and later assess what UX makes the most explicit experience. Thank you! |
Fine-grained or shared settings - I would prefer the |
Perfect, that’s why I asked ;-) I’ll shuffle the board tomorrow and start
working on this tomorrow afternoon.
We’ll likely use threads (futures) to fetch an arbitrary number quicker.
Thanks for the swift response!
…On Wed, 26 Oct 2022 at 18:06, David Hoover ***@***.***> wrote:
@heitorlessa <https://github.com/heitorlessa>
Fine-grained or shared settings - I would prefer the List[Dict] approach.
The big win there is being able to do a transform for some but not all
parameters.
Key or path - I would use the absolute path. In my particular case I could
have used get_parameters and discarded unused parameters, but I didn't
want to fetch secrets that I didn't need. If you had a mix of common and
app specific parameters being able to use different root absolute paths
would be useful.
—
Reply to this email directly, view it on GitHub
<#1040 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZPQBCFSVA5CQZNWV3HQ3TWFFJJHANCNFSM5PIHNPOQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hey @hooverdc draft PR is ready for UX review (used a dict to improve UX): #1678 I have two questions for you before moving forward:
UX import json
from typing import Any
from aws_lambda_powertools.utilities.parameters.ssm import get_parameters_by_name
params: dict[str, Any] = {
"/db/proxy_arn": {"max_age": 300}, # override caching to 5 minutes
"/cdk-bootstrap/hnb659fds/version": {},
"/dev/service/trip_ingestion/api/keys": {"max_age": "60"},
"/develop/service/amplify/auth/userpool/arn": {},
"/develop/service/amplify/auth/userpool/clientId": {},
"/develop/service/amplify/deployment/deploymentBucket": {},
"/develop/service/booking/statemachine/processBooking": {"transform": "json"}, # final value will be dict
"/develop/service/loadtest/csv/token": {},
"/develop/service/loadtest/csv/user": {},
"/develop/service/loyalty/messaging/queue": {},
}
def lambda_handler(event, context):
ret = get_parameters_by_name(parameters=params, max_age=30) # 30 seconds in-memory caching by default
return {
"statusCode": 200,
"body": json.dumps(ret),
} *Faster. I did two tests within Lambda runtime:
Quick results
Without much further digging, this is largely due to CPU slicing in Lambda (one real core only at ~1.7G), combined with LWP cost and SSM throttling. |
Pasting here from another customer on the error handling question.
|
Is there a reason for using the GetParameter operation in a loop vs the GetParameters operation? I assumed it would be the latter, but I see how that does limit the granularity of the decrypt option to per API call instead of per parameter. |
Great, this unblocks me, thank you!!
Primarily because of |
Quick list of Pros and Cons for using
I'll give it a try on using both: This would require customers to have both
|
Phew, this was challenging due to the flexiblity. Moved to use both Tested with 10 params as before, and tried with 20 to confirm slicing too - all with 128M. Depending how much time I'll have tomorrow (admin day), I'll decide on whether to postpone for another release, or include graceful error handling in a subsequent release. Big progress nonetheless, as I had to address some tech debt and refactored a great chunk of this utility + strict typing in some areas. |
This is finally done - discovered more bugs as I had to refactor other parts to play nice. This should be released by EOD and will auto-close when available in both PyPi and Lambda Layer/SAR. |
This is now released under 2.2.0 version! |
hey @hooverdc this is now available as part of v2.2.0 release (Lambda Layer v13): https://github.com/awslabs/aws-lambda-powertools-python/releases/tag/v2.2.0 Docs have been updated to show case both Let me know if that doesn't address your original ask. |
Thank you @heitorlessa! |
Is your feature request related to a problem? Please describe.
I have several functions in a severless application with several SSM parameters under the same path. Each function only needs access to some parameters and most functions will share some parameters but not all. I don't want functions to have access to parameters they don't require. I also don't want to call
get_parameter
for each parameter in order to keep cold start times down. I would like to be able to specify the parameter names and return them in one batch.Describe the solution you'd like
A
get_parameters_by_name
function that accepts a list of strings of parameter names and returns a dict similar to theget_parameters
function, but with the full parameter path as the key (presumably you could call this with parameters on different paths).https://docs.aws.amazon.com/cli/latest/reference/ssm/get-parameters.html#get-parameters
Describe alternatives you've considered
Writing my own wrapper function that calls
get_parameters
fromboto3
.Additional context
N/A
The text was updated successfully, but these errors were encountered: