Skip to content
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

How to Use Input element inside an event bridge ? #4370

Closed
1 task
willianmascimiano opened this issue Dec 8, 2024 · 2 comments
Closed
1 task

How to Use Input element inside an event bridge ? #4370

willianmascimiano opened this issue Dec 8, 2024 · 2 comments
Assignees
Labels
bug This issue is a confirmed bug. p2 This is a standard priority issue response-requested Waiting on additional information or feedback. scheduler service-api This issue is caused by the service API, not the SDK implementation.

Comments

@willianmascimiano
Copy link

Describe the bug

Im starting a FARGATE application with eventbridge api boto3 python, and its working fine.

However ive setup a ENV VARIABLES in FARGATE cluster definition tasks, and it works fine if i run it manualy in create tasks dashboard.

When begin using The API i receive this error, even using a STRING o JSON Format, with INPUT parameter inside Target.EcsParameters

Erros:

  • ERROR:root:An error occurred: Parameter validation failed:
    Invalid type for parameter Target.Input, value: {'PartitionKey': 'string'}, type: <class 'dict'>, valid types: <class 'str'>

-Invalid type for parameter Target.Input, value: {'VAR1': 'string'}, type: <class 'dict'>, valid types: <class 'str'>

ERROR:root:An error occurred: An error occurred (ValidationException) when calling the CreateSchedule operation: Unable to convert target input to TaskOverride, JSON syntax error in input: [Source: (String)"{"VAR1": "string"}"; line: 1, column: 11]

`
response = client.create_schedule(
Name=f"NOME", # Nome do agendamento
Description='NOME',
ScheduleExpression='cron(55 16 8 * ? *)', # Exemplo: Executa todos os dias ao meio-dia UTC
ScheduleExpressionTimezone=self.timezone , # Fuso horário da expressão CRON
#TaskCount=1, # Número de tarefas a serem executadas
Target={
'Arn': 'x', # Substitua pelo ARN do destino
'RoleArn': 'x', # Substitua pelo ARN do papel com permissões
'EcsParameters': { # Configurações específicas para ECS
'TaskDefinitionArn': 'x', # Substitua pelo ARN da Task Definition
'LaunchType': 'FARGATE', # Tipo de execução (EC2 ou FARGATE)
'NetworkConfiguration': {
'awsvpcConfiguration': { # Configurações de rede para FARGATE
'Subnets': ['y'], # Substitua pelos IDs das sub-redes
#'SecurityGroups': ['1'], # Substitua pelo ID do Security Group
'AssignPublicIp': 'DISABLED' # Define se o IP público será atribuído
}
},

            },
           'Input': {
        'VAR1': '1'
    },
           

        },
         
        State='ENABLED',  # Habilitar o agendamento
        #StartDate=datetime(2024, 12, 4),  # Data de início opcional
        FlexibleTimeWindow={
            'Mode': 'OFF'  # Sem flexibilidade no horário de execução
        },
        
    )

`

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Create a scheduled event on event bridge, with the parameters to apply when runs my container.

Current Behavior

I cant go on.

Reproduction Steps

Wen i try to run the code i has this error.

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.35.76

Environment details (OS name and version, etc.)

macos

@willianmascimiano willianmascimiano added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Dec 8, 2024
@tim-finnigan tim-finnigan self-assigned this Dec 10, 2024
@tim-finnigan
Copy link
Contributor

Thanks for reaching out. The create_schedule command makes a request to the underlying CreateSchedule API, and the API is returning that ValidationException.

The documentation for the Input parameter notes:

Input (string)

The text, or well-formed JSON, passed to the target. If you are configuring a templated Lambda, AWS Step Functions, or Amazon EventBridge target, the input must be a well-formed JSON. For all other target types, a JSON is not required. If you do not specify anything for this field, EventBridge Scheduler delivers a default notification to the target.

Have you tried converting the dict to a string and passing that? For example:

import json

# ... (rest of your imports and setup)

# Prepare the input as a JSON string
input_override = json.dumps({
    "containerOverrides": [
        {
            "name": "your-container-name",  # Replace with your container name
            "environment": [
                {
                    "name": "VAR1",
                    "value": "1"
                }
                # Add more environment variables as needed
            ]
        }
    ]
})

response = client.create_schedule(
    Name=f"NOME",
    Description='NOME',
    ScheduleExpression='cron(55 16 8 * ? *)',
    ScheduleExpressionTimezone=self.timezone,
    Target={
        'Arn': 'x',  # Replace with your target ARN
        'RoleArn': 'x',  # Replace with your role ARN
        'EcsParameters': {
            'TaskDefinitionArn': 'x',  # Replace with your task definition ARN
            'LaunchType': 'FARGATE',
            'NetworkConfiguration': {
                'awsvpcConfiguration': {
                    'Subnets': ['y'],  # Replace with your subnet IDs
                    'AssignPublicIp': 'DISABLED'
                }
            },
        },
        'Input': input_override,  # Use the JSON string here
    },
    State='ENABLED',
    FlexibleTimeWindow={
        'Mode': 'OFF'
    },
)

You can usually find more guidance in a service's User/Developer Guide, for example here for EventBridge — but I'm not sure if there is an example for this specific use case.

@tim-finnigan tim-finnigan added service-api This issue is caused by the service API, not the SDK implementation. p2 This is a standard priority issue scheduler response-requested Waiting on additional information or feedback. and removed needs-triage This issue or PR still needs to be triaged. labels Dec 10, 2024
@willianmascimiano
Copy link
Author

Well, thanks for the help, now it worked very well.

I was doing the input at wrong way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. p2 This is a standard priority issue response-requested Waiting on additional information or feedback. scheduler service-api This issue is caused by the service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

2 participants