Hey Prefect team, I am trying to connect to AWS? I...
# prefect-community
s
Hey Prefect team, I am trying to connect to AWS? I am trying to integrate by passing ACCESS_KEY and SECRET_KEY but I couldn't.
f
@Sai Srikanth are you setting them locally? If, yes maybe this link helps: https://docs.prefect.io/core/idioms/secrets.html#setting-secrets So for my GCP Account I put this as an env variable:
export PREFECT__CONTEXT__SECRETS__GCP_CREDENTIALS=xxxx
So in your case it should be
export PREFECT__CONTEXT__SECRETS__AWS_ACCESS_KEY=xxxx
export PREFECT__CONTEXT__SECRETS__AWS_SECRET_KEY=xxxx
Not sure though if you need to put the AWS in front…
s
I stored the access_key and secret_key local and the same names are present in Prefect-Secret as well.
from prefect.tasks.secrets import PrefectSecret
from prefect.client import Secret
from prefect import task, Flow
import prefect
from prefect.tasks import aws
from prefect.utilities.aws import get_boto_client
from prefect.utilities.tasks import defaults_from_attrs
import datetime
import json
#Connect to Prefect
client = prefect.Client()
access_key = Secret("ACCESS_KEY").get()
secret_access_key = Secret("SECRET_ACCESS_KEY").get()
creds= {"ACCESS_KEY":access_key, "SECRET_ACCESS_KEY":secret_access_key}
aws_credentials= json.dumps(creds)
print(aws_credentials)
#Connect to AWS
# lambda_client = boto3.client('lambda', aws_access_key_id=access_key, aws_secret_access_key=secret_access_key)
@task(max_retries=2, retry_delay=datetime.timedelta(seconds=5))
def InvokeLambdaFunction():
    
prefect_lambda= prefect.tasks.aws.lambda_function.LambdaList(master_region="ap-southeast-2", function_version="ALL", marker=None, max_items=50)
    
prefect_lambda.run(credentials=aws_credentials)
    
# prefect_s3 = prefect.tasks.aws.s3.S3List(bucket='oes-cloud-trail-logs')
    
# prefect_s3.run(credentials=aws_credentials)
flow = Flow("Invoke-lambda", tasks=[InvokeLambdaFunction])
# flow.run() We could run our flow locally using the flow's run method but we'll be running this from Cloud!
flow.register(project_name="Test PoC")
flow.run()
j
Hi @Sai Srikanth - have you stored your secrets in Prefect Cloud? You can access that through the "Team" menu on the top nav bar of the Cloud UI: